Copied
$securityreport = @() $schemaGUID = @{} $ErrorActionPreference = 'SilentlyContinue' Get-ADObject -SearchBase (Get-ADRootDSE).schemaNamingContext -LDAPFilter '(schemaGUID=*)' -Properties name, schemaGUID | ForEach-Object {$schemaGUID.add([System.GUID]
$_.schemaGUID,$_.name)} Get-ADObject -SearchBase "CN=Extended-Rights,$((Get-ADRootDSE).configurationNamingContext)" -LDAPFilter '(objectClass=controlAccessRight)' -Properties name, rightsGUID | ForEach-Object {$schemaGUID.add([System.GUID]$_.rightsGUID,$_.name)} $ErrorActionPreference = 'Continue' # Get a list of AD objects. $AOs = @(Get-ADDomain | Select-Object -ExpandProperty DistinguishedName) $AOs += Get-ADOrganizationalUnit -Filter * | Select-Object -ExpandProperty DistinguishedName $AOs += Get-ADObject -SearchBase (Get-ADDomain).DistinguishedName -SearchScope Subtree -LDAPFilter '(objectClass=*)' | Select-Object -ExpandProperty DistinguishedName ForEach ($AO in $AOs) { $securityreport += Get-Acl -Path "AD:\$AO" | Select-Object -ExpandProperty Access | Select-Object @{name='organizationalunit';expression={$AO}}, ` @{name='objectTypeName';expression={if ($_.objectType.ToString() -eq '00000000-0000-0000-0000-000000000000') {'All'} Else {$schemaGUID.Item($_.objectType)}}}, ` @{name='inheritedObjectTypeName';expression={$schemaGUID.Item($_.inheritedObjectType)}}, ` * } # Filter by single user and export to a CSV file. $User ='Username' $securityreport | Where-Object {$_.IdentityReference -like "*$User*"} | Select-Object IdentityReference, ActiveDirectoryRights, OrganizationalUnit, IsInherited -Unique | Export-Csv -Path "D:\report\permissions.csv" -NoTypeInformation