List Scope Variables and Values

This topic contains 1 reply, has 2 voices, and was last updated by  Curtis Smith 1 year, 11 months ago.

  • Author
    Posts
  • #31549

    Paul Lozancich
    Participant

    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

    Curtis Smith
    Participant

    Yes, check out the Get-Variable cmdlet

You must be logged in to reply to this topic.