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