gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:18:21 25 4
gpt4 key购买 nike

目前以下是我启动 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\""

最佳答案

如果您使用 PowerShell 2.0,您可以使用 -file PowerShell.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"

如果您使用的是 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'"

关于powershell - 使用批处理文件 (.bat) 运行 PS1 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6605039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com