Public/Get-UserGroups.ps1
Function Get-UserGroups { <# .SYNOPSIS Provide a search value or user object to either find or expand into relevant data .NOTES Name: Get-User Author: Luke Hagar Version: 1.0 DateCreated: 5/14/2021 .EXAMPLE Get-UserGroups -Identity "Luke.Hagar" .EXAMPLE Get-UserGroups -Identity "CN=Luke Hagar (2187284),OU=Users,OU=CEN,OU=CE,OU=REGIONS,DC=wfm,DC=pvt" .EXAMPLE $UserObject | Get-UserGroups .EXAMPLE Get-UserGroups -Identity "Luke.Hagar" .LINK #> [CmdletBinding()] param ( [Parameter( ValueFromPipeline, ValueFromPipelineByPropertyName )] [Alias("SamAccountName", "DistinguishedName", "GUID", "SID", "EmployeeID", "mail", "UserPrincipalName")] $Identity = $ENV:USERNAME ) BEGIN { } PROCESS { Foreach ($SearchValue in $Identity) { $UsersGroups = (Get-UserInfo $SearchValue).Memberof $UsersGroups | Get-Group } } END { } } |