使用批处理文件 (.bat) 运行 PS1 脚本

dwy*_*ane 5 powershell vmware batch-file virtual-machine powercli

目前以下是我启动 VMware vSphere PowerCLI 命令提示符的路径。我希望sample.ps1使用批处理文件自动运行我的脚本。如何sample.ps1合并到此路径并创建批处理文件?

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""
Run Code Online (Sandbox Code Playgroud)

JPB*_*anc 4

如果您使用的是PowerShell 2.0,则可以使用-filePowerShell.exe的参数

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -file "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
Run Code Online (Sandbox Code Playgroud)

如果您使用的是 PowerShell 1.0,则可以通过这种方式使用 -command 参数

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -command "& 'C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'"
Run Code Online (Sandbox Code Playgroud)