Ich habe folgende Informationen in der get-help -full start-process
Dokumentation gefunden:
# Startet einen PowerShell-Prozess mit den Berechtigungen "Als Administrator ausführen".
PS C:> Start-Prozess powershell.exe -verb runas
Das Beste, was ich sagen kann, runas.exe
kann Ihren Benutzer ändern, aber Ihre Berechtigungen werden nicht erhöht. Allerdings basiert auf dem obigen Zitat, Powershell - Start-Process
Prozess kann verwendet werden, um dies zu tun, so landete ich tun das folgende in meine up - sudo
Funktion, die Arbeit gut genug zu sein scheint:
$MY_PROFILE_TMP="$Env:TMP\my_profile_tmp"; Function Init-TMP() { #Make sure my personal tmp directory exists if (!(Test-Path $MY_PROFILE_TMP)) { mkdir $MY_PROFILE_TMP | Out-Null } } Function As-Admin() { Init-TMP #Create unique temp filenames to capture stderr and stdout $GUID=New-Guid $ADMIN_OUT="$MY_PROFILE_TMP\$($GUID)_OUT.txt" $ADMIN_ERR="$MY_PROFILE_TMP\$($GUID)_ERR.txt" #Remove temp files if for some anomoly or error they already exist rm -ErrorAction Ignore $ADMIN_OUT rm -ErrorAction Ignore $ADMIN_ERR #Start powershell with elevated permissions and write to the tmp out and error files #Without the &{}, invalid commands like `sudo dinosaur` don't get #captured to the error file Start-Process powershell "& { $args } 2>$ADMIN_ERR > $ADMIN_OUT" -Verb runas -Wait -WindowStyle Hidden #Write to the current console the out and error results from the elevated process #TODO ideally, we'd read from these as a stream so the order would be correct... cat $ADMIN_ERR -Delimiter None | Write-Error cat $ADMIN_OUT #Remove the temp files rm -ErrorAction Ignore $ADMIN_OUT rm -ErrorAction Ignore $ADMIN_ERR } #Make an alias "sudo" New-Alias -Name sudo -Value As-Admin