Solved

EWS private contact

Posted on 2014-10-15
2
348 Views
Last Modified: 2014-10-16
Hello,
 
I am using the script below to export all users fields necessary but I need to also find all users with a contact marked as private.  I cannot find any information online regarding "private" in order to complete the script.  I figured it would be best to bring it to the forums and maybe someone can help.  Any help would be appreciated. Thanks in advance.
 
[String] $AccountNames = "D:\test1.txt"
 foreach ($mbxName in Get-Content $AccountNames) {
    [Int] $intCount = 0
     $dllPath = "c:\Program Files\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll"
     [Void] [Reflection.Assembly]::LoadFile($dllPath)
 
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2)
 
$Service.AutodiscoverUrl($mbxName, {$True})
 $RootFolderID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::contacts, $mbxName)
 
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($Service, $RootFolderID)
 
 
 
# this is the section to export contact items out of contacts folder only
 
 
 
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10000,0)

$findResults = $Service.FindItems($rootFolderid,$view)

 
 
foreach($item in $findResults)
 
  {
 
  """$mbxName"",""$($item.GivenName)"",""$($item.MiddleName)"",""$($item.Surname)"",""$($item.CompleteName.Suffix)"",""$($item.CompanyName)"",""$($item.PhysicalAddresses[0].Street)"",""$($item.PhysicalAddresses[0].City)"",""$($item.PhysicalAddresses[0].State)"",""$($item.PhysicalAddresses[0].PostalCode)"",""$($item.PhysicalAddresses[0].CountryOrRegion)"",""$($item.PhoneNumbers[1])"",""$($item.PhoneNumbers[2])"",""$($item.PhoneNumbers[11])"",""$($item.PhoneNumbers[9])"",""$($item.PhoneNumbers[3])"",""$($item.EmailAddresses[0].Address)"",""$($item.EmailAddresses[1].Address)"""
 
  }
 
 
 
#  this is the section to export contact items out of ALL contacts sub folder only
 
 
 
$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10)
 
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
 
$Response = $RootFolder.FindFolders($FolderView)
 
 
 
ForEach ($folder in $Response.Folders)
 
{
 
 
 
$view1 = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10000,0)

$findResults1 = $Service.FindItems($folder.id,$view1)

 
 
foreach($item in $findResults1)
 
  {
 
  """$mbxName"",""$($item.GivenName)"",""$($item.MiddleName)"",""$($item.Surname)"",""$($item.CompleteName.Suffix)"",""$($item.CompanyName)"",""$($item.PhysicalAddresses[0].Street)"",""$($item.PhysicalAddresses[0].City)"",""$($item.PhysicalAddresses[0].State)"",""$($item.PhysicalAddresses[0].PostalCode)"",""$($item.PhysicalAddresses[0].CountryOrRegion)"",""$($item.PhoneNumbers[1])"",""$($item.PhoneNumbers[2])"",""$($item.PhoneNumbers[11])"",""$($item.PhoneNumbers[9])"",""$($item.PhoneNumbers[3])"",""$($item.EmailAddresses[0].Address)"",""$($item.EmailAddresses[1].Address)"""
 
  }
 
 
 
 
 
}
 }
0
Comment
Question by:ehanchar
2 Comments
 
LVL 40

Accepted Solution

by:
Vasil Michev (MVP) earned 500 total points
ID: 40383732
You need to check the Sensitivity property of the item. In your example, should be $findResults1.Items[0].Sensitivity
0
 

Author Closing Comment

by:ehanchar
ID: 40384476
""$($item.Sensitivity)"""

worked like a charm.  Appreciate the help.
0

Featured Post

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
A brief introduction to what I consider to be the best editor for PowerShell.
In this video we show how to create a Distribution Group 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 >>…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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