【问题标题】:Set-UnifiedGroup is not recognized as the name of a cmdletSet-UnifiedGroup 未被识别为 cmdlet 的名称
【发布时间】:2020-03-28 23:54:35
【问题描述】:

我编写了一个连接到 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、函数、脚本文件或可运行程序的名称。检查名称的拼写,如果包含路径,请验证路径是否正确,然后重试。

【问题讨论】:

标签: powershell office365 exchange-server


【解决方案1】:

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

detailed MS article 描述了如何在远程工作站上使用管理工具。如果链接失效,以下是一些相关部分:

安装Exchange Management Tools,如果尚未完成。

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

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

FWIW,脚本使用Invoke-Expression,通常是not a great idea。可能,

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

也可以。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多