我尝试从命令提示符启动一个名为“long name here.ps1”的长 powershell 脚本。但我也试图确保它在 powershell 中作为管理员命令运行。我在 powershell 中设置了所有执行策略,因此我使用了ss64 set-executionpolicy command guide for powershell来使 powershell 正常工作。但是我正在尝试使用另一个 stackoverflow 问题中的解决方案,该问题涉及以管理员身份运行命令。我正在运行一个需要以管理员身份执行 powershell 脚本 (.ps1) 的批处理脚本,我不介意用户是由 UAC 提示还是输入密码。我目前正在使用以下命令:
powershell.exe -command "&{ Start-Process powershell -ArgumentList '-noprofile -file "C:\long name here.ps1"' -verb RunAs}"
我在底部的https://ss64.com/ps/powershell.html找到了这个命令,其中详细介绍了如何以管理员身份运行 powershell 命令。该代码的问题在于我的 powershell 脚本 1. 有参数,而 2. 有一个长名称。我已经尝试了这个命令的许多不同的迭代,但没有成功,下面列出了那些不起作用的:
powershell.exe -command "&{ Start-Process powershell -ArgumentList '-noprofile -file C:\long` name` here.ps1' -verb RunAs}"
powershell.exe -command "&{ Start-Process powershell -ArgumentList '-noprofile -file:"C:\long name here.ps1' -verb RunAs}"
此外,我完全不知道如何将参数发送到实际脚本。