使用Microsoft Graph更新用户联系人电子邮件地址



我正在尝试使用powerShell中的microsoft.graph模块更新电话号码和电子邮件地址,以更新联系人的电子邮件地址和电话号码。

身份验证是通过具有所需权限的应用程序注册完成的。

要输入的数据从AAD中提取并存储在变量$AadUser 中

正在尝试将电子邮件地址更新为username@domain.com我得到以下信息:

Update-MgUserContact -ContactId $CurrentContact.Id -UserId $ContactManagementMailboxId -EmailAddresses @{$AadUser.Mail = $AadUser.DisplayName}
Update-MgUserContact : The annotation 'domain.com' was targeting the instance annotation 'username'. Only the 'odata.type' annotation is allowed to target an instance annotation.
At line:1 char:1
+ Update-MgUserContact -ContactId $CurrentContact.Id -UserId $ContactMa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: ({ UserId = 424c...GraphContact1 }:<>f__AnonymousType38`3) [Update-MgUserContact_UpdateExpanded1], RestException`1
+ FullyQualifiedErrorId : RequestBodyRead,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUserContact_UpdateExpanded1

我确信用于传递电子邮件地址的哈希表有问题,但我看不出是什么。。。

@{$AadUser.Mail=$AadUser.DisplayName}

看起来不正确,它应该是一个对象数组,其中对象有两个属性名称和地址,例如

Update-MgUserContact -ContactId $contact.Id -EmailAddresses @{name="Sue";address="sue@dom.com"}

在你的例子中,类似

-EmailAddresses @{name=$AadUser.DisplayName;address=$AadUser.Mail}

应该工作

最新更新