2011-03-31 28 views
1

很简单:PowerShell脚本只能运行在PowerShell中,而不是作为参数传递给powershell.exe

> powershell.exe -command "& '\\RemoteServer\c$\My Script.ps1'" 

不会在所有的工作。在记事本中打开My Script.ps1,仅此而已。同时,

> powershell 
PS > &"\\RemoteServer\c$\My Script.ps1" 

工作得很好(脚本执行)。

我不得不使用caspol工具,因为我的脚本依赖于二进制模块,但我不明白这可能是什么问题。

对这个问题的原因有什么想法?

谢谢!

回答

1

尝试...

powershell.exe . '\\RemoteServer\c$\My Script.ps1' 
1

尝试...

powershell.exe -nologo -command "&{\\RemoteServer\c$\My Script.ps1}" 
0

也许你的问题是你的脚本名称的空白区域,这里是一个解决方案,如果你想从调用CMD.EXE

C:\>powershell.exe -nologo -command "&{$a=\"\\RemoteServer\c$\My Script.ps1\";& $a}" 

\"防止cmd.exe的从解释"字符

如果你想将它执行到powershell.exe命令提示符:

PS C:\>powershell.exe -nologo -command "&{`$a='\\WM2008R2ENT\c$\temp\Aff le loup.ps1';& `$a}" 

$ prevent powershell.exe from interpreting $`字符

希望它可以帮助

JP

相关问题