powershell - 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、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
解决方案
该错误是由于缺少 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
也可以。
推荐阅读
- java - 在 java 中使用 StreamingFileSink 创建镶木地板文件
- php - 使用 laravel,是否可以使用 back()->withInput() 中的旧值填充表?
- java - 如何在 Firebase 数据库 Android Studio 中保持领先地位
- javascript - 为远程服务器加载 JS 脚本
- reactjs - React 字体真棒图标在生产中更大
- html - Google App Script (GAS)-Web App-网页上的成功消息/提示,而不是浏览器中的弹出窗口
- python - Python从键盘缓冲区获取数据
- python - 在 Fast API 中使用上下文管理器作为全局依赖项
- php - 加载失败
/json.so:未定义符号:zend_get_properties_for - wordpress - Wordpress + Plesk + Git + 本地环境的设置