I have created following script(test.ps1) and I am executing it from command line as "powershell .\test.ps1"
Write-Host(Start-Transcript -Path "D:\logs.txt")
$remoteScript = {
Write-Host "Remote Log"
}
Invoke-Command -ConnectionUri $uri -Credential $creds -ScriptBlock $remoteScript
Write-Host "Local Log"
Write-Host(Stop-Transcript)
However in the log file generated after executing script, I do not see the log statement either remote or local. This used to work with Powershell 3.0 but recently I upgraded to Powershell 4.0 and it stopped working.
Has anyone faced similar issue or is aware of any other way to capture output from remote and local commands?
Thanks,
Gaurav
Here is a hotfix from Microsoft to resolve this issue:
https://support.microsoft.com/en-us/kb/3014136
It is also discussed here, in Technet
https://social.technet.microsoft.com/Forums/windowsserver/en-US/cecc4f32-28c8-4bdc-be63-49ce3d396625/powershell-4-starttranscript-does-not-log-writehost?forum=winserverpowershell
From the Hotfix site:
On a server that's running Windows Server 2012 R2, you encounter one or more of the following issues when you use PowerShell:
- Issue 1
The Start-Transcript cmdlet does not capture write-host calls, as seen in the following script example:
Start-Transcript -path $env:TEMP\transcript.txt
Write-Host Hello World
Stop-Transcript
Get-Content $env:TEMP\transcript.txt
In this case, "Hello World" does not appear in the transcript.txt file as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With