• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5057
  • Last Modified:

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.
0
AhmedAliShaik
Asked:
AhmedAliShaik
  • 2
  • 2
  • 2
2 Solutions
 
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 McKillopCommented:
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
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
Jamie McKillopCommented:
$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

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now