我的想法是先获取当前目录 然后提权 然后再set-location
到当前目录 但是实现起来问题很大
Start your code here $currentPwd= (Get-Location).Path $currentPwd #admin $currentWi = [Security.Principal.WindowsIdentity]::GetCurrent() $currentWp = [Security.Principal.WindowsPrincipal]$currentWi if( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){ $boundPara=($MyInvocation.BoundParameters.Keys|foreach{ '-{0} {1}'-f$_,$MyInvocation.BoundParameters[$_]} )-join' ' $currentFile=(Resolve-Path$MyInvocation.InvocationName).Path $fullPara=$boundPara+' '+$args-join' ' Start-Process"$psHome\powershell.exe"-ArgumentList "$currentFile$fullPara"-verb runas return } powershell.exe Set-Location "$currentPwd"