powershell - 在Office 365中通过Powershell使用CSV创建新邮箱

标签 powershell office365

我需要通过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

拜托,怎么了?
你能帮助我吗?

最佳答案

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

或者只是不使用此参数。

关于powershell - 在Office 365中通过Powershell使用CSV创建新邮箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32315386/

相关文章:

angular - 如果我无法确定生产中需要什么重定向 URI,我该如何使用 OAuth2?

sharepoint - 终止 SharePoint Office 365 中的工作流而不删除关联任务

Powershell 脚本无法将 Register-ScheduledJob 作为 Azure 资源管理器 CustomScriptExtension 执行

powershell - invoke-command 似乎不起作用 - 我是否使用 winrm.cmd 正确配置 TrustedHosts?

PowerShell 2.0 以及如何处理异常?

powershell - 在 IIS 8 应用程序池中为多台服务器启用自动启动属性

azure - Office365:在收件箱 powershell 中关注

office365 - 如何通过自定义守护程序和图形 REST API 访问多个用户的 OneDrive 文件?

powershell - 通过 .lnk 文件通过管道传输到可执行文件

office365 - Airwatch 和 Office365 集成