需要写个脚本自动开启power shell得最高权限(Unrestricted)

需要写个脚本自动开启power shell得最高权限,脚本在win10,win7上都可以运行。

别人的,你看看

知识点
自动检测当前控制台是否是以管理员权限打开,如果不是,重新打开新的控制台运行当前脚本。
将绑定的参数BoundParameters和非绑定的参数$args,发送给新的控制台。
脚本

param( $a, $b )
#region 关键代码:强迫以管理员权限运行
$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
}
#endregion

#region 测试脚本片段
"a=$a, b=$b"
($args -join ' ')
Write-Host '执行完毕,按任意键退出...'
Read-Host
#endregion