从 powershell 脚本执行 powershell.exe(在 ISE 中运行,但不在脚本中运行)
我是这些很棒的 Power shell 世界的新手。我的脚本有问题,非常感谢您的帮助。
我有一个脚本“cmd4.ps1”,需要运行另一个脚本“Transfer.ps1”,该脚本需要接收 3 个字符串参数,并且需要作为与“cmd4.ps1”不同的其他进程运行。
cmd4.ps1:
$Script="-File """+$LocalDir+"\Remote\Transfer.ps1"" http://"+$ServerIP+"/Upload/"+$FileName+" "+$ServerIP+" "+$LocalIP Start-Process powershell.exe -ArgumentList $Script
弹出后,$Script
中包含一个类似于
-File "c:\temp re\Remote\Transfer.ps1" http://10.1.1.1/Upload/file.txt 10.1.1.1 10.1.1.10
包含使用 -File
参数运行 Powershell.exe 脚本的语法的值,以及三个参数Transfer.ps1 需要 ("http://10.1.1.1/Upload/file.txt", 10.1.1.1, 10.1.1.10
)。
当我在 PowerShell ISE 中编写这些指令时,我可以看到每个值都是正确的,并且 PowerShell.exe 使用正确的值执行,一切正常!,但如果我将这些指令放入“cmd4.ps1”脚本中,它就不起作用,我意味着参数有问题,因为我可以看到它启动了 powershell 但它永远不会结束。
I'm new to these awesome Power shell world. I have a problem with script and really apreciate your help.
I have a script "cmd4.ps1" that needs to run another script "Transfer.ps1" that needs to receive 3 strings params and it needs to be run as other process thead different to "cmd4.ps1".
cmd4.ps1:
$Script="-File """+$LocalDir+"\Remote\Transfer.ps1"" http://"+$ServerIP+"/Upload/"+$FileName+" "+$ServerIP+" "+$LocalIP Start-Process powershell.exe -ArgumentList $Script
After ejecution, the $Script
cointain a value similar to
-File "c:\temp re\Remote\Transfer.ps1" http://10.1.1.1/Upload/file.txt 10.1.1.1 10.1.1.10
containing the syntax to use -File
parameter to run a script of Powershell.exe, and three parameters that Transfer.ps1 needs ("http://10.1.1.1/Upload/file.txt", 10.1.1.1, 10.1.1.10
).
When I write these instructions in PowerShell ISE I can see every values are right and PowerShell.exe is executed with right values, everything work fine!, but if I put these instructions inside "cmd4.ps1" script it doesn't work, I mean something is not right with parameters because I can see it start powershell but it never ends.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-ArgumentList
需要一个字符串参数数组而不是单个字符串。请尝试以下操作:请注意,您可以简化参数的字符串构造,如上所示。
-ArgumentList
is expecting an array of string arguments instead of a single string. Try this instead:Note that you can simplify the string construction of the args as shown above.
你为什么不把它放在cmd4.ps1 中?
Why don't you put this in cmd4.ps1?