Get-ADUserGroupMembership

I often find myself running the following PowerShell command to figure out a user’s AD group membership:

Get-ADUser <username> -Properties MemberOf | Select -Expand MemberOf

I’ve written a little helper function that lives in my PowerShell profile (at the moment to replace this with the following syntax:

Get-ADUserGroupMembership <username>

Here’s the (very simple) code for the function. No error handling, mind you, but it saves me a bit of typing each time.

function Get-ADUserGroupMembership {
  Param
    (
       [parameter(Mandatory=$true)]
       [string]$Username
    )
    
    Get-ADUser $username -Properties MemberOf | Select -Expand MemberOf
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s