Public/Get-Group.ps1
Function Get-Group { <# .SYNOPSIS Provide a search value or Group object to either find or expand into relevant data .NOTES Name: Get-Group Author: Luke Hagar DateCreated: 5/14/2021 .EXAMPLE Get-Group -Identity "Reboot" .EXAMPLE Get-Group -Identity "CN=reboot,OU=Distribution Groups,OU=CE,OU=REGIONS,DC=wfm,DC=pvt" .EXAMPLE $GroupObject | Get-Group .EXAMPLE Get-Group -Identity "CE CEN IT HELPDESK" -Membership .LINK #> [CmdletBinding()] param ( [Parameter( ValueFromPipelineByPropertyName, Mandatory )] [Alias("SamAccountName", "DistinguishedName", "SID", "mail")] $Identity, [string[]]$Properties = @("Name", "mail", "samaccountname", "whenCreated", "whenChanged", "Members", "Memberof"), [string[]]$Select = @("Name", "mail", "samaccountname", "whenCreated", "whenChanged", "Members", "Memberof"), [switch] $F ) BEGIN { } PROCESS { Write-Debug "Properties Requested: $Properties" Write-Debug "Properties Selected: $Select" Foreach ($SearchValue in $Identity) { if ($F) { $Array = Get-ADGroup -Filter "SamAccountName -eq '$SearchValue' -or DistinguishedName -eq '$SearchValue' -or SID -eq '$SearchValue' -or mail -eq '$SearchValue'" -Properties $Properties | Select-Object $Select Get-FlattenedArray $Array } else { Get-ADGroup -Filter "SamAccountName -eq '$SearchValue' -or DistinguishedName -eq '$SearchValue' -or SID -eq '$SearchValue' -or mail -eq '$SearchValue'" -Properties $Properties | Select-Object $Select } } } END { } } |