Powershell Standard Verbose to a variable -
i've written script this, use $output1
in order redirect output of standard verbose.
$output1 = $( cmdlet1 [some parameters] -verbose | % { cmdlet2 [other parameters] -verbose } ) 4>&1
when not store standard verbose in variable, prints in powershell in way, newline. when capture standard verbose in $output1
and save in file, prints in 1 long single line.
how can store in variable standard verbose in way?
as far know there no easy syntax this. why? because pipeline output otherwise interfere verbose, warning , error messages. there still workaround, little more complex. redirect verbose output temporary file, content, remove file. take look:
$resultfile = [system.io.path]::gettempfilename(); 1| % { $x = [system.io.path]::gettempfilename(); rm $x -verbose } 4>$resultfile $result = cat $resultfile rm $resultfile
in example:
$resultfile = [system.io.path]::gettempfilename(); $( cmdlet1 [some parameters] -verbose | % { cmdlet2 [other parameters] -verbose }) 4>&1 $output1 = cat $resultfile rm $resultfile
Comments
Post a Comment