I am writing a VB.NET PowerShell Cmdlet which needs to start, and later stop, the Transcript file (Start-Transcript). So how do I manage to run the command Start-Transcript from within the cmdlet? I have tried this:
Dim myRunSpace As Runspace = RunspaceFactory.CreateRunspace()
myRunSpace.Open()
Dim MyPipeline As Pipeline = myRunSpace.CreatePipeline()
MyPipeline.Commands.AddScript("Start-Transcript -Path $pwd\session.txt")
Dim results As Collection(Of PSObject) = MyPipeline.Invoke()
myRunSpace.Close()
Produces the error "Start-transcript : this host does not support transription". Yet when I enter the command manually no error is produced and transcription starts.