Update AD Scripts/Get AD Users and their Group Memberships.ps1

This commit is contained in:
2025-08-05 14:59:41 +00:00
parent 712c5d2098
commit 1d84755a68
@@ -1,9 +1,9 @@
Get-ADUser -Filter * -Properties SamAccountname, DisplayName | ForEach-Object { Get-ADUser -Filter * -Properties SamAccountname, DisplayName | ForEach-Object {
New-Object PSObject -Property @{ New-Object PSObject -Property @{
UserName = $_.DisplayName UserName = $_.DisplayName
oSamAccountname = $_.SamAccountname oSamAccountname = $_.SamAccountname
UserOU = ($_.DistinguishedName -split ",",2)[1] UserOU = ($_.DistinguishedName -split ",",2)[1]
Groups = (Get-ADPrincipalGroupMembership $_.SamAccountname | Select-Object -ExpandProperty Name) -join Groups = (Get-ADPrincipalGroupMembership $_.SamAccountname | Select-Object -ExpandProperty Name) -join
"," ","
} }
} | Select-Object oSamAccountname, UserName, UserOU, Groups | Export-Csv -Path "C:\Temp\Script Cache\Audit\ADUserandGroupMembers.csv" -NoTypeInformation } | Select-Object oSamAccountname, UserName, UserOU, Groups | Export-Csv -Path "C:\Temp\Script Cache\Audit\ADUserandGroupMembers.csv" -NoTypeInformation