我正在尝试在 cmd 命令行中运行 PowerShell 脚本。有人给了我一个例子,它起作用了:
powershell.exe -noexit "& 'c:\Data\ScheduledScripts\ShutdownVM.ps1'"
但问题是我的 PowerShell 脚本有输入参数,所以我尝试了,但它不起作用:
powershell.exe -noexit "& 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' "
错误是:
The term 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' is not recognized as the name of a cmdlet, function,
我该如何解决这个问题?
最佳答案
您需要将参数与文件路径分开:
powershell.exe -noexit "& 'D:\Work\SQLExecutor.ps1 ' -gettedServerName 'MY-PC'"
另一个可以使用文件参数和位置参数简化语法的选项:
powershell.exe -noexit -file "D:\Work\SQLExecutor.ps1" "MY-PC"
关于windows - 如何在 CMD 中运行 PowerShell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16436405/