簡體   English   中英

隱藏TFS發行日志中的導入模塊輸出

[英]Hide Import-Module output from TFS Release logs

我正在使用TFS 2015版本。 我有一個非常簡單的腳本:它導入模塊並運行另一個腳本。 問題是我在TFS發行日志中看到了Import-Module日志,但無法隱藏它們。 例:

# ScriptRunner.ps1
Import-Module MyModule -DisableNameChecking -Global
& ".\script.ps1"

當我使用以下命令在本地運行此命令時,我看不到Import-Module命令的任何輸出:

powershell "path\ScriptRunner.ps1" 

在TFS發行版中,我具有“目標計算機上的PowerShell”任務,並且運行相同的腳本ScriptRunner.ps1 這就是我在日志中看到的:

Deployment started on target machine...
Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MyModule\MyModule.psm1'
Exporting function 'My-Function-1'.
...
Exporting function 'My-Function-10'.
The 'My-Function-1' command in the MyModule module was imported, but because its name does not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.
The command name 'My-Function-1' from the module 'MyModule' contains one or more of the following restricted characters: # , ( ) { } [ ] & - / \ $ ^ ; : " ' < > | ? @ ` * % + = ~
Importing function 'My-Function-1'.
...

如何記錄? 我指定DisableNameChecking標志。 我試圖通過更改腳本中的Import-Module行來隱藏此消息,但這無濟於事:

[void](Import-Module MyModule -DisableNameChecking -Global)
Import-Module MyModule -DisableNameChecking -Global | Out-Null
Import-Module MyModule -DisableNameChecking -Global -WarningAction SilentlyContinue

您可以將$ ErrorActionPreference標志設置為Silentlycontinue。 那應該解決問題。 請注意,將這一行添加到腳本時,整個腳本都會更改“錯誤操作首選項”。

$ErrorActionPreference = "Silentlycontinue"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM