Set-UnifiedGroup无法识别为cmdlet的名称

时间:2019-12-04 08:17:18

标签: powershell office365 exchange-server

我写了一段代码以连接到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,函数,脚本文件或可运行程序的名称。检查名称的拼写,或者是否包含路径,请确认路径正确,然后重试。

2 个答案:

答案 0 :(得分:0)

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

https://www.w3schools.com/css/css_overflow.asp描述了如何使用远程工作站上的管理工具。如果出现链接腐烂,请参考以下相关部分:

安装detailed MS article(如果尚未安装)。

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

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

FWIW,脚本使用的是Invoke-Expression,通常是Exchange Management Tools

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

也可以。

答案 1 :(得分:0)

我的帐户没有 Exchange 管理员角色,因为我们在组织中实施了 Azure AD 特权身份管理。我能够加载模块,登录,例如使用 Get-UnifiedGroup,但缺少 Set-UnifiedGroup

激活 Exchange 管理员角色并重新加载 PowerShell 模块后,CMDlet 可用。