简体   繁体   English

PowerShell 如何抑制错误消息

[英]PowerShell How to suppress error messages

Whenever I run Update-Help, I get tons of errors.每当我运行 Update-Help 时,都会出现大量错误。 I've given up trying to resolve these, it's just how PowerShell works, some help file definitions always fail to update (but if anyone knows how to resolve these I would be interested to try).我已经放弃尝试解决这些问题,这就是 PowerShell 的工作方式,一些帮助文件定义总是无法更新(但如果有人知道如何解决这些问题,我会很感兴趣尝试)。

So, I want to suppress the errors from my script that updates this stuff every month.所以,我想抑制每个月更新这些东西的脚本中的错误。

I've tried Update-Help -EA silent and Update-Help -EA silent | Out-Null我试过Update-Help -EA silentUpdate-Help -EA silent | Out-Null Update-Help -EA silent | Out-Null but in both cases, the error messages are still sprayed on the screen in red. Update-Help -EA silent | Out-Null但在这两种情况下,错误消息仍然以红色喷洒在屏幕上。

Does anyone know hot to suppress these?有谁知道热压制这些?

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

This will help you:这将帮助您:

Update-Help -ErrorAction SilentlyContinue

Or或者

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

Do not forget that WarningAction exists.不要忘记存在WarningAction

I'm not sure it applies to you, but I was trying to suppress the 'SystemRestorePointCreationFrequency' output of Checkpoint-Computer and it is a Warning--not an Error.我不确定它是否适用于您,但我试图抑制 Checkpoint-Computer 的“SystemRestorePointCreationFrequency”输出,这是一个警告——而不是一个错误。 The following will suppress that warning:以下将抑制该警告:

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

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

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