【发布时间】:2022-01-24 20:59:31
【问题描述】:
我正在尝试在 cmd 命令行中运行 PowerShell 脚本。有人给了我一个例子,它奏效了:
powershell.exe -noexit "& 'c:\Data\ScheduledScripts\ShutdownVM.ps1'"
但是问题是我的PowerShell脚本有输入参数,所以我试了一下,还是不行:
powershell.exe -noexit "& 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' "
错误是:
术语 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' 未被识别为 cmdlet、函数的名称,
我该如何解决这个问题?
【问题讨论】:
-
您确定要使用 -noexit 吗?这意味着当您的脚本完成时,shell 会挂起,可能会阻止 CMD 中批处理文件的执行。
标签: windows powershell batch-file cmd