powershell - 更新 Office 365 用户的某些 "My Contacts"的电子邮件地址

标签 powershell

我们有一个从其他提供商迁移来的 Office 365 部署。用户拥有大量的个人通讯簿(在 Outlook 中标记为“我的联系人”)。

与我们密切合作的一家公司最近更改了域名。我需要更新用户的个人联系人,以便“@foobar.com”的电子邮件地址现在转到“@foobar.co.uk”。让用户自己做这件事带来的麻烦远大于其值(value)。

似乎有很多关于使用 PowerShell 更新全局通讯簿的指南,但没有关于如何更新单个用户的“我的联系人”的指南。

是否有用于在 PowerShell 中编辑个人用户的个人联系人的任何示例等或代码片段?或者任何性质相似的示例脚本?

最佳答案

当我在 Contacts 中设置联系人时,我可以确认以下代码片段对我有用。文件夹,它成功重写并正确保存了联系人。请注意,我也正在更改 DisplayName字段,因为(在我所在的位置)在某些情况下不会重写该字段以反射(reflect)正确的地址。

警告:我现在已禁用(注释)此代码中的实际工作。因为它将挖掘您的Contacts中未知的(数千或更多?)数量的联系人。仅文件夹(不是全局地址列表,使用此代码)。

只有当您通过 Write-Host 验证看到预期输出时,才应取消注释中间的三行。命令。

我不愿意发现我试图帮助您的尝试导致了重写大量联系人信息以及恢复过程中的麻烦。

也就是说,这绝对应该给您一个良好的开端,您可以根据需要/需要进行修改。

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")
$Contacts = $namespace.GetDefaultFolder(10)

foreach ($Entry in $Contacts.Items)
{

    if ($Entry.Email1Address -like "*foobar*")
    {
        $newAddress = $Entry.Email1Address -replace "foobar.com", "foobar.co.uk"
        $newDisplayName = $Entry.Email1DisplayName -replace "foobar.com", "foobar.co.uk"

        #UNCOMMENT the below lines, once you've confirmed it will work as expected for you
        #$Entry.Email1Address = $newAddress
        #$Entry.Email1DisplayName = $newDisplayName
        #$Entry.Save()

        #COMMENT OUT (or don't) the three below lines, once you've validated that this will work in your environment
        $Entry | Format-Table FullName,Email1Address,Email1DisplayName
        Write-Host ("Would convert " + $Entry.Email1Address + " to... " + $newAddress)
        Write-Host ("Now displayed as " + $Entry.Email1DisplayName + " to... " + $newDisplayName)
    }

}

$olApp.Quit | Out-Null
[GC]::Collect()

进一步披露:在企业端运行此操作之前,请考虑备份您的联系人列表。另外,请参阅我上面关于某些企业系统未在标准 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16777475566e6f6c3875797b" rel="noreferrer noopener nofollow">[email protected]</a> 中显示电子邮件地址的注释。格式。因此,为什么我还提供了 Write-Host命令,让您查看是否有类似的问题。如果是这样,请告诉我们,我将尝试进一步研究如何引用该正确内容(如果可能)

您可能必须向用户提供批处理文件,这样您就不必解释如何运行它,也取决于什么 ExecutionPolicy在您的企业中配置。

我的设置说明:Windows 7、Office 365(特别是 Outlook 2016 - 16.0.6366.2062)和 PowerShell 5.0,尽管我觉得这里的 cmdlet 和引用是通用的。如果您遇到问题,那就是。

关于powershell - 更新 Office 365 用户的某些 "My Contacts"的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235070/

相关文章:

windows - 在 Powershell 中删除 file1 中存在于 file2 中的行

powershell - 无法从 Exchange cmdlet 捕获/重定向警告

powershell - WinRM 无法完成操作。验证指定的计算机名称是否有效

powershell - 生成随 secret 码

powershell - 使用WinSCP和PowerShell无法删除名称中带有方括号的目录

powershell - 运行powershell时 "- <"是什么意思?

powershell - 使用 powershell 将文本附加到文件

powershell - 通过 Out-GridView 管道后获取原始对象

image - PIL : module object has no attribute 'resize'

powershell - 使用名为length的键的Powershell哈希表