Created
June 9, 2020 16:26
-
-
Save NicholasLeader/b5ae229ad39611edb6e658205b4758c2 to your computer and use it in GitHub Desktop.
PowerShell example of script to determine details of a set of AD users, given an AD group filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# Nicholas Leader | |
6.9.2020 | |
Report on AD users that belong to certain AD groups | |
Including manager details | |
#> | |
#date stamp in string | |
$DateStamp = get-date -Format MM.dd.yyyy.mm | |
#What group you're looking for | |
$groupfilter = 'exampleFilter*' | |
#doing some calculated properties | |
#including returning the groups the users are members of that we're filtering on | |
#also details on the users managers | |
Get-ADGroup -Filter {name -like $groupfilter } | | |
Get-ADGroupMember -Recursive | | |
Get-ADUser -Properties title,Company,Country, AccountExpirationDate, DisplayName, EmployeeType,Mail,manager | | |
Select-Object name, samaccountname, title,Company,Country, AccountExpirationDate, DisplayName, EmployeeType,Mail,memberof, @{ | |
name='manager';expression = {(get-aduser $_.manager).name}},@{ | |
name='managerTitle';expression = {(get-aduser -Properties title $_.manager).title}}, @{ | |
name='managerDivision';expression = {(get-aduser -Properties Division $_.manager).Division}}, @{ | |
name='managerManager';expression = {(get-aduser (get-aduser -Properties Manager $_.manager).Manager).name}},@{ | |
name='memberOfgroup';expression = {($_.memberof | Get-ADGroup -Filter {name -like $groupfilter}).name}} | | |
export-csv -NoTypeInformation "groupReport.$DateStamp.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment