shellcommander
shellcommander

Reputation: 37

PowerShell Script Logging

I call a PowerShell Script trough c#.net. After calling the script nothing happens, and I don’t get any error to track the issues. I need the output of the complete script execution.

Is it possible to write the PowerShell log/output somewhere?

Upvotes: 1

Views: 731

Answers (1)

Knuckle-Dragger
Knuckle-Dragger

Reputation: 7056

Assuming the Start-Transcript method will not work because we are not in the PS console session, this leaves us with a few alternatives in Powershell v 2.0.

One method I like is Write-Host combined with Add-Content, so I can both see and retain certain results. If you are in the pipeline you can use the Out-File -Append

Write-Host $Data;Add-Content $Output $Data;

Out-File -Append -FilePath $Output

Tee-Object cannot append from Powershell v2, so I would avoid it unless you cannot.

Upvotes: 2

Related Questions