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

Posted on 2012-09-10
Last Modified: 2012-09-11
As per our requirement we need to Pull the legacyexchangeDN & showinaddressbook attribute of all contacts in a OU.>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.
Question by:AhmedAliShaik
    LVL 18

    Accepted Solution

    Try this:

    $Users = Get-Mailbox -OrganizationalUnit ''
    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.
    LVL 37

    Assisted Solution

    by:Jamie McKillop

    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

    Open in new window

    LVL 18

    Expert Comment


    May I know what is meaning for:

    what is different with $ReportObj=''
    LVL 37

    Expert Comment

    by:Jamie McKillop
    $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.

    LVL 2

    Author Comment

    Both the scripts are working perfect.

    Thank you Guys.
    LVL 2

    Author Closing Comment

    Thank you Dear

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Email statistics and Mailbox database quotas You might have an interest in attaining information such as mailbox details, mailbox statistics and mailbox database details from Exchange server. At that point, knowing how to retrieve this information …
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now