簡體   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