Running a command as Administrator using PowerShell?

后端 未结 26 2847
粉色の甜心
粉色の甜心 2020-11-22 09:41

You know how if you\'re the administrative user of a system and you can just right click say, a batch script and run it as Administrator without entering the administrator p

26条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 10:03

    Here is how to run a elevated powershell command and collect its output form within a windows batch file in a single command(i.e not writing a ps1 powershell script).

    powershell -Command 'Start-Process powershell -ArgumentList "-Command (Get-Process postgres | Select-Object Path | Select-Object -Index 0).Path | Out-File -encoding ASCII $env:TEMP\camp-postgres.tmp" -Verb RunAs'
    

    Above you see i first launch a powershell with elevated prompt and then ask that to launch another powershell(sub shell) to run the command.

提交回复
热议问题