PowerShell for Windows Admins

Apr 24 2010   3:32PM GMT

Windows Groups

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

We can find the groups on a machine using WMI

PS> Get-WmiObject -Class Win32_Group | select Name, Description, SID, LocalAccount | format-list

Name         : Administrators
Description  : Administrators have complete and unrestricted access to the computer/domain
SID          : S-1-5-32-544
LocalAccount : True

etc etc

But what would be good would if we could also check membership at the same time

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
Get-WmiObject -Class Win32_Group | 
foreach {
    “`n$($_.Name)”
    “$($_.Description)”
    “SID: $($_.SID)”
    “Local = $($_.LocalAccount)”
    “Members:”
   
    $query = “ASSOCIATORS OF {Win32_Group.Domain='” `
    + $_.Domain + “‘,Name='” + $_.Name `
     + “‘} WHERE ResultClass=Win32_UserAccount”   
    Get-WmiObject -Query $query | 
    select Caption

}

By now this format should be familiar.  We get the groups and for each group we use the ASSOCIATORS query to find the group members using the  Win32_UserAccount. We use string substitution to display the group information and display the caption property to get the domain and user name

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: