【发布时间】:2014-02-19 06:40:50
【问题描述】:
我正在尝试使用 Powershell 将外部联系人添加到 MS Exchange。
$username = "username@domain.com"
$password = "password"
$secure_password = $password | ConvertTo-SecureString -AsPlainText -Force
$credencial = New-Object System.Management.Automation.PSCredential ($username, $secure_password)
$session_name = "office365_session"
foreach($tmp in Get-PSSession){
if ($tmp.Name -eq $session_name) {
$opened_session = Get-PSSession -Name $session_name
}
}
if ($opened_session -eq $null) {
$opened_session = New-PSSession -Name $session_name -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $credencial -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue -ErrorAction Stop
Import-PSSession $opened_session -AllowClobber -WarningAction SilentlyContinue -ErrorAction Stop -DisableNameChecking | Out-Null
}
New-MailContact -Name "test" -DisplayName "test user" -ExternalEmailAddress "some.email@mail.com" -FirstName "Test" -LastName "User"
但是没有找到“New-MailContact”命令并抛出错误:
New-MailContact : The term 'New-MailContact' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
如何运行“New-MailContact”命令?也许我需要导入其他东西,或者可能有另一种添加联系人的方法?
【问题讨论】:
-
在导入会话后添加管理单元。
标签: powershell