Is there a way to display the content added to a variable when it is created?

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Vandrey Trindade Vandrey Trindade 6 months, 2 weeks ago.

  • Author
    Posts
  • #61378
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Hi,

    Newbie question, is there a way to show the content of a variable when it is created?
    e.g. Create a variable that contains an array with all distribution groups and display its content on the console

    $Groups = Get-Distribution

    I was wondering something like the Tee-Object (shows on the console and saves the result on a file) but without creating a file...

  • #61383
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant
    New-Variable -Name Groups -Value (Get-Distribution) -PassThru

    For new variables. And

    Set-Variable -Name Groups -Value (Get-Distribution) -PassThru

    to change the value

  • #61419
    Profile photo of Jeremy Murrah
    Jeremy Murrah
    Participant

    not sure what version they added it to, but you can also use the -outvariable parameter like this:

    Get-Distribution -OutVariable Groups
    

    That will display on the screen and put it into $Groups

  • #61425
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Jeremy Murrah,

    Thanks, that was the best way for me!

You must be logged in to reply to this topic.