sharepoint 脚本 强迫以管理员权限运行

#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 "$psHomepowershell.exe"   -ArgumentList "$currentFile $fullPara"   -verb runas 
 return
} 
#endregion
原文地址:https://www.cnblogs.com/wodegui/p/5001179.html