How to remove the MobilePhone from my Public Folder contacts?

In case you want to remove the "MobilePhone" property for all your public folder contacts, you can use this script. The same reasoning applies for other properties, with the mention that you need to load the corresponding extended property for them.



-The script requires EWS Managed API 2.2, which can be downloaded here:
-You need to be connected to Exchange Online when you run the script (copy/paste it into a Notepad file and save it with the extension ".ps1"):


DISCLAIMER: This application is a sample application. The sample is provided "as is" without warranty of any kind. Microsoft further disclaims all implied warranties including without limitation any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the samples remains with you. in no event shall Microsoft or its suppliers be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss arising out of the use of or inability to use the samples, even if Microsoft has been advised of the possibility of such damages). Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you.

$PF = Read-Host -Prompt "Public Folder identity (e.g. \PF1, \PF1\SubPF1)"

Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"

$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList Exchange2013_SP1

#Provide the credentials
 $credential = Get-Credential -Message "Type the credentials of the mailbox that you intend to use to connect to the public folder"

$service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList $credential.UserName, $credential.GetNetworkCredential().Password

#Exchange Online URL
 $service.Url= new-object Uri("")

function Convert($c)
$aiItem = New-Object Microsoft.Exchange.WebServices.Data.AlternatePublicFolderId

$aiItem.FolderId = $c

$aiItem.Format = [Microsoft.Exchange.WebServices.Data.IdFormat]::HexEntryId

$convertedId = $service.ConvertId($aiItem, [Microsoft.Exchange.WebServices.Data.IdFormat]::EwsId)

$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId($convertedId.FolderId)

return $folderid;

$SourcePF = Convert (Get-PublicFolder $PF).EntryId

$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

$MobilePhone = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x3A1C, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)


$ItemView = new-object Microsoft.Exchange.WebServices.Data.ItemView(1000)



$FindItemResults = $service.FindItems($SourcePF,$ItemView)


write-host "$($FindItemResults.TotalCount) contact(s) has/have been found in the source folder" -ForegroundColor White


foreach($Item in $FindItemResults.Items)

if ($Item.ItemClass -match "IPM.Contact" -and $Item.ExtendedProperties.Value)

$Contact = [Microsoft.Exchange.WebServices.Data.Contact]::Bind($service,$Item.Id,$psPropertySet);

Write-Host "Removing the MobilePhone for the contact: $($Contact.DisplayName)" -ForegroundColor White






else { Write-Host "The Public Folder is empty!" -ForegroundColor Yellow; break; }

$ItemView.offset += $FindItemResults.Items.Count


while($FindItemResults.MoreAvailable -eq $true)




Comments (0)

Skip to main content