#$domainRoot = [ADSI]"LDAP://ou=exchange,DC=accounts,DC=domain,DC=local" $strDate = get-date -uformat "%Y-%m-%d" $CSVFilePath = 'c:\Users_'+$strDate+'.csv' $entry = Read-Host "Enter domain scope to search: " if ($entry -eq '') { "going to search the root." $root = [ADSI]'LDAP://RootDSE' $entry = $root.DefaultNamingContext.tostring() $entry } $domainscope = "LDAP://" + $entry $domainRoot = [ADSI]$domainScope "Searching: " + $domainRoot # by default this filter finds all disabled mail-enabled users where msExchMasterAccountSID is populated -essentially Linked Mailboxes. $filter = "(&(objectClass=user)(mailnickname=*)(userAccountControl:1.2.840.113556.1.4.803:=2)(msExchMasterAccountSID=*)(msExchHideFromAddressLists=FALSE))" # Properties set to variables for the get-mailbox cmdlets below $proplist = @("distinguishedName","displayName","mailnickname") "got to here" "Display Name, Associated External Account, SendAs Users" | out-file -filepath $CSVFilePath -encoding ascii # now find all users in the $domainRoot path specified above and add the write personal information for the linked master account. # If you do want to search subfolders of the specified OU, change "Subtree" from "OneLevel" $userFinder = new-object System.DirectoryServices.DirectorySearcher($domainRoot, $filter, $proplist, [System.DirectoryServices.SearchScope]::Subtree) $userFinder.PageSize = 100 $results = $userFinder.FindAll() foreach ($result in $results) { if ($result.Properties["distinguishedname"][0].StartsWith("CN=SystemMailbox{")) { # Skip SystemMailbox objects } else { $thisUserDN = $result.Properties["distinguishedname"][0] $useralias = $result.Properties["mailnickname"][0] $thisUserDN $MAS = get-mailbox $thisUserDN $DisplayName = $MAS.displayname $AEA=$MAS.LinkedMasterAccount $arSendAs = $MAS | get-adpermission | select user, extendedrights | where {($_.extendedrights -like 'send-as') -and ($_.user -notlike '*SELF*') -and ($_.user -notlike '*S-1-5*')} forEach ($User in $arSendAs) { """" + $DisplayName + """," + $AEA + "," + $user.user | out-file -filepath $CSVFilePath -encoding ascii -append } } }