Pull the legacyexchangeDN & showinaddressbook attribute of all contacts in a OU.

As per our requirement we need to Pull the legacyexchangeDN & showinaddressbook attribute of all contacts in a OU.

Abd.com->test->contacts

In the contacts OU i have 10k contacts. I need to pull the report of all users

firstname lastname legacyExchangeDn showInAddressBook

Can anyone share me powershell command for the same.
LVL 2
AhmedAliShaikAsked:
Who is Participating?
 
suriyaehnopCommented:
Try this:

$Users = Get-Mailbox -OrganizationalUnit 'domain.com/OU1'
foreach ( $User in $Users){

Get-Mailbox -Identity $user.alias | ft LegacyExchangeDN,@{Label='ShowInAddressBook';expression={(Get-AdUser -Identity $user.alias -Properties *).ShowInAddressBook}}

}

Open in new window


Pleae note that you need to have following modules added to your PowerShell session:

Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
Add-PSSnapin -Name Microsoft.Exchange.Management.Powershell.Support
Import-Module -Name ActiveDirectory

If you run the cmdlet on Exchange Management Shell, both Exchange Management Powershell already added.
0
 
Jamie McKillopIT ManagerCommented:
Hello,

The script above is for mailboxes, not contacts. Try this:

$Report = @()
Get-MailContact -ResultSize unlimited -OrganizationalUnit 'OU=contacts,DC=company,DC=com' | % {
	$contact = Get-Contact $_
	$Reportobj = "" | select Firstname,LastName,legacyExchangeDN,HiddenFromAddressBook
	$Reportobj.firstname = $contact.firstname
	$Reportobj.lastname = $contact.lastname
	$Reportobj.legacyExchangeDN = $_.legacyexchangedn
	$Reportobj.hiddenfromaddressbook = $_.hiddenfromaddresslistsenabled
	$Report += $Reportobj
}
$report

Open in new window


JJ
1
 
suriyaehnopCommented:
JJ,

May I know what is meaning for:

$Report
$ReportObj=""
what is different with $ReportObj=''
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Jamie McKillopIT ManagerCommented:
$ReportObj is an object created to hold all the values required for each contact. This gets reused for each contact so the $Report array is created to compile all the $ReportObj.

JJ
0
 
AhmedAliShaikAuthor Commented:
Both the scripts are working perfect.

Thank you Guys.
0
 
AhmedAliShaikAuthor Commented:
Thank you Dear
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.