PowerShell script as VisualStudio Post-Build Event loses Logs of Transcript

My Script contains the command Start-Transcript, which is creating a log file.

If I start the PowerShell.exe and call the Script it is creating the log file correctly.

If I start the script on the ISE, it gives me an error (This Host doens’t support Logs/Records):

Start-Transcript : Dieser Host unterstützt keine Aufzeichnungen.
Bei Zeile:12 Zeichen:17
+ Start-Transcript <<<< "C:\transcripts\transcript0.txt" -Path  -Force 
    + CategoryInfo          : NotImplemented: (:) [Start-Transcript], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StartTranscriptCommand

But if I run the script as a Post Build Event, it is not logging.

Can anybody explain me why the script is losing the information of the transript if I start itself with Visual Studio (2013 Professional)?

powershell.exe -executionpolicy bypass -file "$(SolutionDir)PSTranscriptTest.ps1"

My PSVersion-Infos:

4>  Name                           Value                                           
4>  ----                           -----                                           
4>  CLRVersion                     2.0.50727.5485                                  
4>  BuildVersion                   6.1.7601.17514                                  
4>  PSVersion                      2.0                                             
4>  WSManStackVersion              2.0                                             
4>  PSCompatibleVersions           {1.0, 2.0}                                      
4>  SerializationVersion           1.1.0.1                                         
4>  PSRemotingProtocolVersion      2.1                                             

My Script contains:

Start-Transcript -Path "C:\transcripts\transcript0.txt" -Force
Write-Host "Test With Write Host"
Write-Output "Test With Write Output"
Verbose "Test With Verbose"
$PSVersionTable
Stop-Transcript 

The Output to Screen works. But not to the file.

The file contains:

**********************
Start der Windows PowerShell-Aufzeichnung
Startzeit:    20170302100746
Benutzername: User-PC\User 
Computer:	 USER-PC (Microsoft Windows NT 6.1.7601 Service Pack 1) 
**********************
**********************
Ende der Windows PowerShell-Aufzeichnung
Endzeit: 20170302100746
**********************

Transcript functionality is a function of the hosting application, not the PowerShell engine. For example, it didn’t used to work in the ISE, either. That’s the problem - whatever VS is doing to run the script isn’t supporting the transcript.

Thank you. How can I know, if a functinality is a function of the hosting application or the PowerShell engine?
From where can I get this information?

Can you recommend me an alternative of the start-transcript for simple logging with the PowerShell engine?

You learn those things through experience and by asking questions, as you’ve done here.

I would probably write my own logging function.

:slight_smile: Thank you.

I’ll redirect the stream with a parameter to a file.

powershell.exe -executionpolicy bypass -file "$(SolutionDir)PSTranscriptTest.ps1" > RedirectStream.log