List Scope Variables and Values

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 11 months, 4 weeks ago.

  • Author
  • #31549
    Profile photo of Paul Lozancich
    Paul Lozancich

    Is there any easy routine for listing all the variables and their values for a give scope?

    If I have the following script scope variables:
    $script:var1 = 1
    $script:var2 = 2
    $script:var3 = 3

    For debugging, I can write the following to list their values:
    Write-Host "script:var1: $script:var1"
    Write-Host "script:var2: $script:var2"
    Write-Host "script:var3: $script:var3"

    But I have to continually modify it as variables come and go. Any easy way that I can look through an object and get the same results? That way I'd never have to change that part of the debugging script and miss any.

  • #31551
    Profile photo of Curtis Smith
    Curtis Smith

    Yes, check out the Get-Variable cmdlet

You must be logged in to reply to this topic.