强制PowerShell脚本以管理员身份运行

Tom*_*res 5 powershell

我编写了一个PowerShell脚本来安装和启动一些服务.它仅在脚本以管理员身份运行时才有效.有没有办法强制脚本拥有这些权限?

JPB*_*anc 9

如果您使用的是PowerShell V2,您还可以执行以下操作:

Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "Get-Service"'
Run Code Online (Sandbox Code Playgroud)

这将以管理员身份运行"Get-Service",您可以将其替换为您的脚本.