簡體   English   中英

在PowerShell中從遠程會話重定向詳細流

[英]Redirect verbose stream from remote session in PowerShell

我想將遠程會話的詳細輸出保存到變量或文件中

只有普通輸出可以重定向,而冗長輸出則不能。

$VerbosePreference = "Continue"

$s = New-PSSession localhost
$str = (Invoke-Command -Session $s -Verbose -Script {
    $VerbosePreference = "Continue"
    "1"
    Write-Verbose "2"
} *>&1)

"str=$str"

預期產量:

str=1 2

實際輸出:

VERBOSE: 2
str=1

重定向腳本塊的詳細輸出。 使用任一

$s = New-PSSession -ComputerName localhost
$str = Invoke-Command -Verbose -Session $s -ScriptBlock {
    "1"
    Write-Verbose "2" -Verbose 4>&1
}
"str=$str"

甚至

$s = New-PSSession -ComputerName localhost
$str = Invoke-Command -Verbose -Session $s -ScriptBlock {
    $(
        "1"
        Write-Verbose "2" -Verbose
    ) *>&1
}
"str=$str"

Nothe按預期工作與默認的詳細偏好即上面的代碼片段$VerbosePreference = 'SilentlyContinue'

暫無
暫無

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

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