Powershell 2:无法抑制警告消息

Lar*_*old 5 powershell warnings

我正在对PowerShell 2中的'set-distributiongroup'进行cmdlet调用.我只是将参数'hiddenFromAddressListsEnabled'的值设置为预定义的布尔值.

但是,无论我尝试什么,如果布尔赋值实际上没有改变'hiddenFromAddressListsEnabled'的当前值,它会显示一条警告消息.

这是我正在调用的主要命令:

set-DistributionGroup -identity TestGroup                  `
                      -hiddenFromAddressListsEnabled=$true
Run Code Online (Sandbox Code Playgroud)

让我们在语义上将我上面的内容定义为"命令".

现在,我尝试添加几种不同的变体,所有变体都具有正确的行继续和语法.以下是这些变体:

command > $null
command 2> $null
command -ErrorAction:silentlycontinue
command -ErrorVariable $throwAway
command -WarningAction:silentlycontinue
command -WarningVariable $throwAway
$var = command
Run Code Online (Sandbox Code Playgroud)

无论上述一个或多个的各种组合如何,我仍然会得到一个黄色警告:消息吐出输出.具体来说,这个:

WARNING: The command completed successfully but no settings of
'<xxxxxx>/Users/TestGroup' have been modified.
Run Code Online (Sandbox Code Playgroud)

关于一个我不理解的关键概念的任何建议?我希望命令不生成此输出,并且我希望它在发生这种情况时以静默方式继续.

谢谢!!

Ral*_*oss 10

我一直试图在停止服务时抑制警告消息:

WARNING: Waiting for service 'Service Description' to finish stopping...
Run Code Online (Sandbox Code Playgroud)

以下对我有用:

Stop-Service $svc.Name -WarningAction SilentlyContinue
Run Code Online (Sandbox Code Playgroud)


Sha*_*evy 2

您可能会遇到此错误:http://connect.microsoft.com/PowerShell/feedback/details/541500/warning-verbose-and-debug-streams-do-not-respect-action-preferences-the-way-they -应该

不管怎样,你的命令应该是这样的:

Set-DistributionGroup -Identity TestGroup -HiddenFromAddressListsEnabled $true
Run Code Online (Sandbox Code Playgroud)