Skip to content

Instantly share code, notes, and snippets.

@azure365pro
Created May 13, 2020 17:15
Show Gist options
  • Save azure365pro/11c555cf78a201fa18aa3b6e98c81966 to your computer and use it in GitHub Desktop.
Save azure365pro/11c555cf78a201fa18aa3b6e98c81966 to your computer and use it in GitHub Desktop.
Export Authoritative Domains and its Respective OU's List (Hosted Environment)
csvde -f C:\OUTempDump.csv -r "(objectclass=organizationalunit)"
$OUdump = Import-CSV C:\OUTempDump.csv
$report = @()
$auths = Get-AcceptedDomain | Where-Object{$_.DomainType -eq 'Authoritative'}
Foreach($Auth in $auths)
{
$Members = $OUdump | Where-Object{$_.upnsuffixes -like "*$auth*"}
$Trick = $Auth.Name
$Total = $Members.Count
$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "OrganizationalUnit" -Value $members.Name
$userObj | Add-Member NoteProperty -Name "Authoritative Domain" -Value $Trick
$report = $report += $userObj
$report | Export-csv -Path C:\OUdump.csv -NoTypeInformation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment