繁体   English   中英

PowerShell 如何抑制错误消息

[英]PowerShell How to suppress error messages

每当我运行 Update-Help 时,都会出现大量错误。 我已经放弃尝试解决这些问题,这就是 PowerShell 的工作方式,一些帮助文件定义总是无法更新(但如果有人知道如何解决这些问题,我会很感兴趣尝试)。

所以,我想抑制每个月更新这些东西的脚本中的错误。

我试过Update-Help -EA silentUpdate-Help -EA silent | Out-Null Update-Help -EA silent | Out-Null但在这两种情况下,错误消息仍然以红色喷洒在屏幕上。

有谁知道热压制这些?

Update-Help : Failed to update Help for the module(s) 'AppvClient, ConfigDefender, Defender, HgsClient, HgsDiagnostics,
HostNetworkingService, Microsoft.PowerShell.ODataUtils, Microsoft.PowerShell.Operation.Validation, Sudo, UEV, Whea,
WindowsDeveloperLicense' with UI culture(s) {en-GB} : Unable to connect to Help content. The server on which Help content is stored
might not be available. Verify that the server is available, or wait until the server is back online, and then try the command again.
At C:\Users\Boss\AppData\Local\Temp\BeginSystemConfig.ps1:571 char:9
+         Update-Help
+         ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToConnect,Microsoft.PowerShell.Commands.UpdateHelpCommand

Update-Help : Failed to update Help for the module(s) 'WindowsUpdateProvider' with UI culture(s) {en-GB} : Unable to retrieve the
HelpInfo XML file for UI culture en-GB. Make sure the HelpInfoUri property in the module manifest is valid or check your network
connection and then try the command again.
At C:\Users\Boss\AppData\Local\Temp\BeginSystemConfig.ps1:571 char:9
+         Update-Help
+         ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand

这将帮助您:

Update-Help -ErrorAction SilentlyContinue

或者

Try {
  Update-Help -ErrorAction Stop
  # Use this method only if you want to halt script on errors
}
Catch {
  # Place action on error here
}

不要忘记存在WarningAction

我不确定它是否适用于您,但我试图抑制 Checkpoint-Computer 的“SystemRestorePointCreationFrequency”输出,这是一个警告——而不是一个错误。 以下将抑制该警告:

Checkpoint-Computer -Description "my description" -RestorePointType "MODIFY_SETTINGS" -WarningAction SilentlyContinue

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM