首页 文章

更新Office 365用户的某些“我的联系人”的电子邮件地址

提问于
浏览
2

我们有一个Office 365部署,从另一个提供程序迁移 . 用户拥有大量的个人通讯簿(在Outlook中标记为“我的联系人”) .

我们密切合作的公司最近更改了其域名 . 我需要更新用户的个人联系人,以便“@ foobar.com”的电子邮件地址现在转到“@ foobar.co.uk” . 让用户自己做这件事要比它值得多麻烦 .

似乎有很多关于使用PowerShell更新全局地址簿的指导,但没有关于如何为各个用户更新“我的联系人”的指导 .

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

1 回答

  • 3

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

    WARNING :我've disabled (commented) the actual work in this code for now. Since it'只会挖掘 Contacts 文件夹中的未知(数千或更多?)个联系人(不是全局地址列表,使用此代码) .

    The three lines in the middle should be uncommented only when you validate you're seeing the expected output via the Write-Host commands.

    我不想发现我帮助你的尝试导致重写大量的联系人和头痛恢复 .

    也就是说,这绝对应该让你先行一步,你可以根据需要/需要进行修改 .

    $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()
    

    Further disclosure :在企业端运行之前,请考虑备份联系人列表 . 另外,请参阅上面的注释,了解一些企业系统没有以标准 abc@xyz.com 格式显示电子邮件地址 . 因此,为什么我还提供了 Write-Host 命令,以便您查看是否存在类似问题 . 如果是这样,请告诉我们,我可能会这样做 . )

    您可能必须使用批处理文件将其提供给用户,因此您不必解释如何运行它,还取决于企业中配置的 ExecutionPolicy .

    关于我的设置的注意事项:Windows 7,Office 365(特别是Outlook 2016 - 16.0.6366.2062)和PowerShell 5.0,虽然我觉得这里的cmdlet和引用是通用的 . 如果你有问题,那就是 .

相关问题