Updates To Contacts Not Saving

Copper Contributor

I have a working script that will connect to a specific mailbox, pull in all the contacts and loop through them.  My script is validating and standardizing certain data (like phone numbers).  Everything is fine, except the updates are not reflected in the contact when viewed after.  Since the update doesn't seem to provide any feedback on success or failure I'm unable to get any insight into what might be wrong.

 

I've shortened my code enough to give you an idea of what I'm doing.  Why aren't the updates saving?

 

param (
    # Identity
    [Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, Position = 1)]$Identity,

    # Credential
    [Parameter(Mandatory = $true, HelpMessage = "Enter Admin Credential with ApplicationImpersonation and Mailbox Import Export roles")]
    [System.Management.Automation.CredentialAttribute()]
    $Credential = (Get-Credential),
    $ExchangeServer,
    [bool]$Recursive,
    [ValidateSet('Exchange2007','Exchange2010','Exchange2013')]$Version = "Exchange2013"
)

[object[]]$Identity = Get-Mailbox $Identity
$PrimarySmtp        = $Identity.PrimarySmtpAddress.ToString()
$ContactFolder      = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Contacts, $PrimarySmtp)
$Rootfolder         = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $ContactFolder)
$View               = new-object Microsoft.Exchange.WebServices.Data.ItemView(500, 0)

while (($contacts = $folder.FindItems($View)).Items.Count -gt 0) {
   $service.LoadPropertiesForItems($contacts, [Microsoft.Exchange.WebServices.Data.PropertySet]::FirstClassProperties)

   foreach ($contact in $contacts) {
      if ($contact.DiaplayName -eq "Test Contact") {
         $contact.PhoneNumbers[[Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::MobilePhone] = "123-456-7890"

         $contact.Update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverWrite)
      }
   }
}

 

0 Replies