【问题标题】:Create new mailboxes using a CSV via Powershell in Office 365在 Office 365 中通过 Powershell 使用 CSV 创建新邮箱
【发布时间】:2015-08-31 16:03:08
【问题描述】:

我需要在 Office 365 中通过 Powershell 创建新邮箱。 我正在使用这个脚本:

$User = "administrator@blablabla.onmicrosoft.com" 
$PWord = ConvertTo-SecureString -AsPlainText -Force -String "P@ssword1"
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection 
Import-PSSession $Session

Import-CSV new.csv | foreach { 
    New-Mailbox -UserPrincipalName $_.UserPrincipalName -displayname $_.DisplayName -password (ConvertTo-SecureString $_.password -AsPlainText -Force) -usagelocation "us" 
}

Get-PSSession | Remove-PSSession

邮箱的详细信息保存在 new.csv 文件中。 请参阅以下示例:

UserPrincipalName,DisplayName,password
clark.kent@blablabla.onmicrosoft.com,Clark Kent,P@ssword1
bruce.wayne@blablabla.onmicrosoft.com,Bruce Wayne,P@ssword1
peter.parker@blablabla.onmicrosoft.com,Peter Parker,P@ssword1

当我运行这个脚本时,我返回错误:

A parameter cannot be found that matches parameter name 'UserPrincipalName'.
    + CategoryInfo          : InvalidArgument: (:) [New-Mailbox], 

ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,New-Mailbox
    + PSComputerName        : outlook.office365.com

请问,怎么了? 你能帮帮我吗?

【问题讨论】:

    标签: powershell office365


    【解决方案1】:

    UPN 参数仅在本地 Exchange 上可用。根据您的 AD 是在本地还是在云端,我建议您先使用此参数创建 AD 帐户,然后再启用邮箱。

    或者干脆不使用这个参数。

    【讨论】:

      【解决方案2】:

      执行此操作的正确方法是通过 MicrosoftOnlineServicesID 参数执行此操作,该参数似乎复制了 UPN

      New-Mailbox -Alias $mailbox.Alias -Name $mailbox.Name -DisplayName $mailbox.DisplayName -ResetPasswordOnNextLogon $true -Password $temporaryPassword -MicrosoftOnlineServicesID $upn -WhatIf
      
      WARNING: After you create a new mailbox, you must go to the Office 365 Admin Center and assign the mailbox a license, or it will
       be disabled after the grace period.
      What if: Creating mailbox "Anna" with User Principal Name "anna@domain.org.pl" in organizational
       unit "EURPR06A004.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/domain.onmicrosoft.com".
      

      完整的故事可以在我的blog 找到,但您只需将 UPN 更改为 MicrosoftOnlineServicesID,它应该可以立即工作。

      【讨论】:

        【解决方案3】:

        尝试使用 -identity 代替 -userprincipalname

        【讨论】:

        • 这行不通。在这种情况下,只有 MicrosoftOnlineServicesID 有效。
        猜你喜欢
        • 1970-01-01
        • 2020-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-19
        • 1970-01-01
        • 1970-01-01
        • 2019-12-22
        相关资源
        最近更新 更多