首页 > 解决方案 > Set-UnifiedGroup 未被识别为 cmdlet 的名称

问题描述

我编写了一个连接到 Exchange 服务器的代码,然后将统一组欢迎消息设置为 false。但由于某种原因,我的会话似乎不起作用。

Write-Host -ForegroundColor Yellow "Trying to establish a session with exchange"
try
{
    $ProxyOptions = New-PSSessionOption -ProxyAccessType IEConfig
    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credentials -Authentication Basic -AllowRedirection -SessionOption $ProxyOptions
    Write-Host -ForegroundColor Green "Succesfully established a session"

    Write-Host -ForegroundColor Yellow "Trying to set Welcome Message to false"

    try
    {
        Import-PSSession $session -DisableNameChecking
        Set-UnifiedGroup $groupAlias -UnifiedGroupWelcomeMessageEnabled:$false
        Write-Host -ForegroundColor Green "Succesfully disabled the welcoming message"
    }
    catch
    {
        $errorMessage = $_.Exception.Message
        Write-Host -ForegroundColor Red "Error occured..."
        Write-Host -ForegroundColor blue $errorMessage
    }
}
catch
{
    Write-Host -ForegroundColor Red "Error while establishing a session"
    $errorMessage = $_.Exception.Message
    Write-Host -ForegroundColor Blue $errorMessage
}

我收到一个错误

术语“Set-UnifiedGroup”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

标签: powershelloffice365exchange-server

解决方案


该错误是由于缺少 Exchange 管理模块引起的。它要么未加载,要么根本未安装。

一篇详细的 MS 文章描述了如何在远程工作站上使用管理工具。在链接失效的情况下,以下是一些相关部分:

安装Exchange 管理工具(如果尚未完成)。

运行加载工具并连接到 Exchange 的脚本:

$CallEMS = ". '$env:ExchangeInstallPath\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "
Invoke-Expression $CallEMS

FWIW,脚本正在使用Invoke-Expression,这通常不是一个好主意。很可能,

. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto -ClientApplication:ManagementShell

也可以。


推荐阅读