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 $output1and 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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -