获取当前用户的所在组

[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups |%{$_.value} |
  ForEach-Object {
    $sid = $_
    $objSID = New-Object System.Security.Principal.SecurityIdentifier($sid)
    $objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
    $objUser.Value
  }

OR

[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups | foreach {
    $objSID = New-Object System.Security.Principal.SecurityIdentifier($_.value)
    $objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
    $objUser.Value
}

 

posted @ 2015-05-08 14:55  dongdonggeorge  阅读(715)  评论(0编辑  收藏  举报