Thursday, November 12, 2015

Get-ADGroup queries the AD for group object items eg names


Get-ADGroup

Command to obtain group names containing 2 specified strings which is then further filtered for the case sensitive instances by the where cmdlet using the -clike operator, the case sensitive version of -like in the where cmdlet.

Get-ADGroup -filter {Name -like "*string1*" -and Name -like "*STrIng2*"} | where {$_.name -clike "*STrIng2*"} | Select-Object name | Sort-Object name

Notes
where is short for Where-Object
Select-Object and Sort-Object can be shortened to Select and Sort
-notlike is also a valid operator for the where object.

This command is useful to include the group description in the output

 get-adgroup -filter {name -like "*mystring*"} -Properties description | select name,description