我有我不想使用批處理文件而以管理員身份運行自己的腳本。Powershell RunAs管理員
問題是,當我運行腳本時,它會打開一個新的管理員窗口,然後立即關閉。
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
Get-AppxProvisionedPackage -Online | Sort-Object -Property DisplayName | Select-Object -Property DisplayName
究竟在哪裏?我在所有行上都嘗試過很多地方,但它仍然退出或拋出參數無法找到的錯誤。 –
傳遞給'Start-Process'的命令行。 – Richard