0

以下の内容のファイルtranscript-test.ps1があります

$log="TestLog{0:yyyyMMdd-HHmm}" -f (Get-Date) $logfile = 'C:\logs\'+$log+'.txt' Start-transcript -path $logfile -force Write-host "このメッセージがログに記録されるかどうかをテストするには" Stop-transcript

Lets say "box1" からスクリプトを実行しようとしましたが、ログ ファイルには以下の内容が含まれています。

** * ** * ** * * Windows PowerShell Transcript Start Start time: 20110105114050 Username : domain\user Machine : BOX1 (Microsoft Windows NT 5.2.3790 Service Pack 2) * ** * ** * ** * Transcript started,出力ファイルは C:\logs\TestLog20110105-1140.txt です

このメッセージがログに記録されるかどうかをテストするには

** * ** * ** * * Windows PowerShell トランスクリプト終了終了時刻: 20110105114050


以下のスクリプトを使用して別のマシンから同じスクリプトを実行すると、ログ ファイルにメッセージが表示されません。

Invoke-command {powershell.exe -ExecutionPolicy Unrestricted -NoProfile -File C:\in ll\transcript-test.ps1} -computername box1 -credential $credential get-credential

ログファイルの内容:

** * ** * ** * * Windows PowerShell Transcript Start 開始時刻: 20110105114201 ユーザー名: DOMAIN\user マシン: BOX1 (Microsoft Windows NT 5.2.3790 Service Pack 2)


** * ** * ** * * Windows PowerShell トランスクリプト終了終了時刻: 20110105114201


リモートで呼び出されたときにスクリプトからログファイルにメッセージを記録する方法はありますか?

ありがとう!サンジーブ

4

2 に答える 2

1

以下は、ローカルおよびリモートの冗長メッセージをトランスクリプトにキャプチャします

$VerbosePreference = "continue"
Start-Transcript -path c:\temp\transcript.txt 

Write-Verbose "here 1"

$job = Invoke-Command cbwfdev01 -ScriptBlock {

    $ErrorActionPreference = "Stop";
    $VerbosePreference = "continue";

    Write-Verbose "there 1";
    Write-Verbose "there 2";
    Write-Verbose "there 3";

} -AsJob 

Wait-Job $job | Out-Null

$VerboseMessages = $job.ChildJobs[0].verbose.readall()

ForEach ($oneMessage In $VerboseMessages) {Write-Verbose $oneMessage}

Write-Verbose "here 2"

Stop-Transcript
于 2016-04-29T15:10:01.620 に答える
0

Invoke-command は、コードをジョブに実行します。これは、私が理解している限り、コンソールのないスレッドであるため、転写はありません。私にとって、あなたが得たものは絶対に正常です。

于 2011-07-08T18:27:11.263 に答える