Powershell Version Used: 3.0
Hello everybody,
I am trying to create a new Powershell pipeline and execute the script inside it, and then get the output it produces into the output variable, but I cannot get any result created inside the object (from the executed script). The thing is that I do not need to manage the $ Error object, which I intend to use to detect errors. Here is an example below:
$ps = [Powershell]::Create() $File = ".\Test2.ps1" $SortedParams = "-Name blah -Key foo" $RootDirectory = Get-Location $ExecutionDirectory = "$RootDirectory\Test3" $ps.AddCommand("Set-Location").AddParameter("Path", "$ExecutionDirectory") write-host "COMMAND 1: " $ps.Commands.Commands.Item(0).CommandText $ps.AddScript("$File $SortedParams") write-host "COMMAND 2: " $ps.Commands.Commands.Item(1).CommandText $output = $ps.Invoke() write-host $output
I should mention that I am trying to use the following 3 methods to create output in a script:
- Write host
- Write output
- Write-Verbose (uses $ ps.Streams.Verbose to try to get the result, but nothing)
Any suggestions or tips you can give are greatly appreciated!
source share