Hi,
You can add the DistinguishedName attribute of the AD user to the output.
$ous = 'C:\temp\ous.txt'
$userlist = 'C:\temp\userlist.csv'
Get-Content -Path $ous | ForEach-Object {
Get-ADUser -Filter * -SearchBase $_ -Properties DisplayName,EmailAddress
} | Select Name,GivenName,Surname,DisplayName,SamAccountName,EmailAddress,DistinguishedName |
Export-Csv -Path $userlist -NoTypeInformation
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.