Last active
July 21, 2020 09:50
-
-
Save tomhebbron/43ae81df738297913bacb16bd17c4f59 to your computer and use it in GitHub Desktop.
Useful PowerShell for extracting / reporting on AD users and groups
This file contains hidden or 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
| Import-Module ActiveDirectory | |
| #users | |
| $users = Get-ADUser -filter * -properties AccountExpirationDate, AccountLockoutTime, AccountNotDelegated, AllowReversiblePasswordEncryption, CannotChangePassword, CanonicalName, Created, Deleted, Description, DisplayName, DistinguishedName, EmailAddress, EmployeeID, EmployeeNumber, Enabled, GivenName, HomeDirectory, HomedirRequired, LastBadPasswordAttempt, LastLogonDate, LockedOut, LogonWorkstations, Modified, Name, PasswordExpired, PasswordLastSet, PasswordNeverExpires, PasswordNotRequired, PrimaryGroup, ProfilePath, SamAccountName, SID, SIDHistory, Surname, Title, TrustedForDelegation, TrustedToAuthForDelegation, UserPrincipalName | |
| #$users | export-clixml "C:\temp\ADUsers.xml" | |
| #Groups (with members) | |
| $groups = Get-ADGroup -filter * -properties CanonicalName, Created, Deleted, Description, DisplayName, DistinguishedName, GroupCategory, GroupScope, ManagedBy, MemberOf, Members, Modified, Name, ObjectCategory, ObjectClass, ObjectGUID, SamAccountName, SID | |
| #$groups | export-clixml "C:\temp\ADGroups.xml" | |
| $users | export-csv -NoTypeInformation AD-users.csv | |
| $groups | export-csv -NoTypeInformation AD-groups.csv | |
| $groups | ForEach-Object {foreach ($m in $_.members) { [System.Tuple]::Create($_.distinguishedname, $m)}} | export-csv -NoTypeInformation -Path C:\temp\ad-groupmembers.csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment