Get-ADGroup
A simple cmdlet for powershell 2 AD management pack to get group information in one line.
Example usage
Define the parameters
Identity takes a range of identifiers for the object. These include "Distinguished Name", "GUID", "SID", and "samaccountname". As all the cmdlets have been designed for interoperability, I find it best to use output from other commands like get-aduser. Full help file here.
In a script
This script gets detailed information about all the groups that user1 is a direct member of.
Powershell without the Management pack
To emulate the second example above, get all universal groups, I have chosen my GC search script to return the information. Note, all group type values have been listed, and of course they can be combined as in this example. To get all universal groups, you need to return both distribution and security groups :
A simple cmdlet for powershell 2 AD management pack to get group information in one line.
Example usage
get-adgroup -identity "domain admins"
get-adgroup -filter 'GroupScope -eq "Universal"'
Define the parameters
Identity takes a range of identifiers for the object. These include "Distinguished Name", "GUID", "SID", and "samaccountname". As all the cmdlets have been designed for interoperability, I find it best to use output from other commands like get-aduser. Full help file here.
In a script
This script gets detailed information about all the groups that user1 is a direct member of.
get-aduser user1 -Properties memberof | select -expandproperty memberof | foreach {get-adgroup $_}
Powershell without the Management pack
To emulate the second example above, get all universal groups, I have chosen my GC search script to return the information. Note, all group type values have been listed, and of course they can be combined as in this example. To get all universal groups, you need to return both distribution and security groups :
#group type values
$UniversalGroup = -2147483640
$DomainLocalGroup = -2147483644
$GlobalGroup = -2147483646
$globalDLGroup = 2
$DomainLocalDLGroup = 4
$UniversalDLGroup = 8
$ObjectCategory = "group"
#run the searcher
$Forest = [System.DirectoryServices.ActiveDirectory.forest]::getcurrentforest()
$GC = $forest.FindGlobalCatalog()
$searcher = $gc.GetDirectorySearcher()
$Searcher.pagesize = 1000
#note the use of the '&' and the '|' as 'and' and 'or'
$searcher.filter = "(&(objectCategory=$ObjectCategory)(|(grouptype=$UniversalDLGroup)(grouptype=$UniversalGroup)))"
$Results = $Searcher.FindAll()
$Results
Comments
Post a Comment