我有一個討厭的問題,我想消除我得到的調試信息,我不是要求在Powershell控制檯和ISE。這是一個令人討厭的,因爲它阻礙了我想要的調試信息。無需驗證的調試信息在Powershell控制檯
我不清楚這是特定於我的腳本工具(WinSCP)還是更通用的PowerShell行爲。
簡而言之,WinSCP.Session.Open
事件不寫出來東西了(好!),但Close()
和Dispose()
方法相當健談,與下面的出現在我的每個調用控制檯。
起初我以爲這可能是在finally
塊中包含語句的結果,但將它們移動到try
塊會產生相同的討厭行爲。
基於一個類似但不相同的問題,我檢查了「偏好變量」。我的股票價值都在最後上市,我試圖改變無濟於事只有一個是「警告首選項」設置爲「默認繼續」,這是沒有效果的
運行示例:
PS F:\> getFirewallContents "AAA" 255.255.227.254
Attempting Session.Open AAA | 255.255.227.254
Completed Session.Open AAA | 255.255.227.254
/var/db/commits exists, last write: 5/8/2015 11:33:22 AM
Closing Session AAA
... two stanzas that follow are the undesired output ......
MemberType : Method
OverloadDefinitions : {System.Void Close()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Void Close()
Name : Close
IsInstance : True
MemberType : Method
OverloadDefinitions : {System.Void Dispose()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Void Dispose()
Name : Dispose
IsInstance : True
Closed Session AAA
function getFirewallContents ([string] $fw_name, [string] $fw_ip) {
$session = New-Object WinSCP.Session
$sessionOptions = New-Object WinSCP.SessionOptions
$xferOptions = New-Object WinSCP.TransferOptions
$sessionOptions.HostName = $fw_ip
$sessionOptions.UserName = "NOPE"
$sessionOptions.Password = "NOT TELLING"
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = $TRUE
$remotefile = "/var/db/commits"
Try {
Write-Host "Attempting Session.Open " $fw_name " | " $sessionOptions.HostName
$session.Open($sessionOptions)
Write-Host "Completed Session.Open " $fw_name " | " $sessionOptions.HostName
if ($session.FileExists($remotefile)) {
Write-Host "$remotefile exists, last write:" $session.GetFileInfo($remotefile).LastWriteTime
} else {
Write-Host "$remotefile NOT FOUND"
}
} Catch {
Write-Host "Something bad happened"
} Finally {
Write-Host "Closing Session $fw_name "
$session.Close
$session.Dispose
Write-Host "Closed Session $fw_name "
}
}
Name Value
---- -----
ConfirmPreference High
DebugPreference SilentlyContinue
ErrorActionPreference Continue
ProgressPreference Continue
VerbosePreference SilentlyContinue
WarningPreference Continue (Tried Silently Continue, no effect)
WhatIfPreference False
發送輸出到位桶。 '$ session.Close | Out-Null'等 –