List Scope Variables and Values

Welcome Forums General PowerShell Q&A List Scope Variables and Values

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 years ago.

  • Author
    Posts
  • #31549

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Yes, check out the Get-Variable cmdlet

The topic ‘List Scope Variables and Values’ is closed to new replies.