PowerTip: Split PowerShell Output Between Console and Variable

PowerTip: Split PowerShell Output Between Console and Variable

Rate This
  • Comments 1

Summary: Learn an easy way to save Windows PowerShell output in a variable and still output to the console.

Hey, Scripting Guy! Question What is an easy way to display Windows PowerShell output from a cmdlet to the console, and yet store the results in a variable at the same time?

Hey, Scripting Guy! Answer Use the OutVariable parameter:

           GSV -OutVariable S

Leave a Comment
  • Please add 4 and 2 and type the answer here:
  • Post
  • Hi

    here another option:

    PS II> gsv | Tee-Object -var s

    PS II> $s

    PS II> ($s=gsv)

    PS II> $s

Page 1 of 1 (1 items)