使用 powershell、cmd 或 python 自动创建 M365 outlook 配置文件

Create M365 outlook profile automatically using powershell, cmd, or python

目标是什么 - 无需 client/user 干预即可自动编写 outlook 配置文件。他们只需点击 Outlook,电子邮件就会在第一时间出现。无需为最终用户设置或配置。

我为一家拥有大约 70 个客户的 MSP 工作。每个客户都为办公应用程序使用 Office E3 许可证,但他们使用第三方公司来托管电子邮件 (intermedia/serverdata)。

这种特殊的差异使得很难使用基于自动发现和 AD 用户的 smtp 地址的 ZeroConfigExchange 自动设置 outlook 配置文件。用户正在使用 Azure AD 连接到计算机,但 Azure AD 不知道用户的 smtp 地址是什么,因为他们没有与微软在线交换,而是与 intermedia/serverdata.

在线交换

所以我一直在努力寻找任何方法来根据电子邮件地址、服务器地址和凭据自动创建 outlook 配置文件;这样当用户第一次到达那里的设备时,它会将 outlook 配置文件添加到那里的帐户。

我调查的内容:

无论如何都在尝试 ZeroConfigExchange - 失败 - 它不知道创建配置文件的 smtp 信息在哪里。

尝试使用 PowerMapi 的 New-MapiProfile - 失败 - 从这里发现:https://superuser.com/questions/1141519/configuring-outlook-with-powershell 这在 office 2016 或 office 365 上不起作用,因为它们更改了凭据设置

尝试使用 O365 配置工具制作包含电子邮件配置文件的自定义版本的办公应用程序 - 失败 - 显然他们从较新的 O365 配置工具中删除了此功能。根据我的研究,这曾经在旧版本中,但现在不存在了: (我没有足够的图片代表点,所以这里是我图片的链接) https://i.ibb.co/jftNVg2/help1.png https://i.ibb.co/8ggz5hg/help2.png

尝试使用我从这里找到的这个 powershell 脚本:

$continue = [System.Windows.Forms.MessageBox]::Show("This will delete any outlook profile on your machine. Do you want to continue?", "Continue?", 'YesNo', 'Question')

if ($continue -eq "Yes")
{
    # Create Outlook COM instance
    Add-Type -assembly "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -comobject Outlook.Application
    
    $namespace = $outlook.GetNameSpace('MAPI')
    
    $outbox = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderOutbox)
    $Drafts = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderDrafts)
    
    
    do
    {
        $set = $outbox.Items
        foreach ($item in $set)
        {
            [void]$item.move($Drafts)
        }
        
        Start-Sleep -Seconds 3 | Out-Null
    }
    while ($outbox.items.count -ne 0)
    
    # Quick rest before killing COM
    Start-Sleep -Seconds 3 | Out-Null
    # Kill Outlook COM instance
    $outlook.Quit() | Out-Null
    [System.Runtime.InteropServices.Marshal]::ReleaseComObject($outlook) | Out-Null
    
    
    if (Get-Process outlook)
    {
        Get-Process outlook | Stop-Process | Out-Null
    }
    
        
    
    if (Test-Path "$Env:appdata\Microsoft\Outlook\")
    {
        Try
        {
            $void = Remove-Item "$Env:appdata\Microsoft\Outlook\" -force -recurse | Out-Null
        }
        Catch
        {
            [void][System.Windows.Forms.MessageBox]::Show("A file was still in use, try again.", "Information", 'OK', 'Error')
        }
        
    }
    
    
    if (Test-Path HKCU:\Software\Microsoft\Office.0\Outlook)
    {
        
        #New-ItemProperty -Path HKCU:\Software\Microsoft\Office.0\Outlook\AutoDiscover -Name ZeroConfigExchange -Value 1 -PropertyType DWORD -Force
        
        Remove-Item "HKCU:\Software\Microsoft\Office.0\Outlook\Profiles\*" -Recurse -Force | Out-Null
        
        Remove-ItemProperty -Path HKCU:\Software\Microsoft\Office.0\Outlook\Setup\ -name First-Run | Out-Null
        
        Start-Process 'C:\Program Files (x86)\Microsoft Office\root\Office16\outlook.exe' | Out-Null
        
    }
    
    else
    {
        #do nothing
    }
    
}
else
{
    [void][System.Windows.Forms.MessageBox]::Show("Nothing was done", "Information", 'OK', 'Information')
    
}

这能够调出电子邮件设置的提示,但无论如何都可以将其包含在此 powershell 脚本中吗?

我也尝试了一些她的 mfcmapi 应用程序e: https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/how-to-create-an-outlook-profile-using-mfcmapi

但是我只是按照微软的文档和研究随机错误并没有真正让我走得更远,我得到了太多的错误。看起来好像 mfcmapi 完全坏了。

昨天我也在这里问了这个问题:https://superuser.com/questions/1640825/autoconfigure-m365-outlook-profile 但我在这个帖子中添加了更多的故障排除方法。我也会向微软提出支持请求,看看有没有什么想法。

如果我为其他人找到好的答案,我会告诉大家。

感谢您的宝贵时间,

你也可以试试ProfMan library (disclaimer: I am its author) - it can be easily used to pre-create an Outlook profile for an Office 365 mailbox - see https://www.dimastr.com/redemption/profman_examples.htm#ROH_Profile_Outlook2016