Getting the value of a variable

Welcome Forums General PowerShell Q&A Getting the value of a variable

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

Hil
 
Participant
1 year, 12 months ago.

  • Author
    Posts
  • #65211
    Hil

    Participant
    Points: 23
    Rank: Member

    This is part of a much larger script with numerous FOR loops. I have just taken the bare essentials of the code and created a new script so that the problem is more easily understandable.

    Problem: I need $Threshold_NEW to display 2500. It is the last line of the code
    Please help.
    Thanks

    Code:
    $Threshold_MSW = 2500
    $Threshold_OMF = 1500
    $Threshold_CCC = 2500

    $ServerZone = "MSW"

    $Threshold_value = "Threshold_$ServerZone"
    $Threshold_NEW = $($Threshold_value)
    write-host $Threshold_NEW

  • #65218

    Moderator
    Points: 24
    Team Member
    Rank: Member

    You could do the following:

    $Threshold_NEW = (Get-Variable -Name "Threshold_$ServerZone").Value
    $Threshold_NEW = Get-Variable -Name "Threshold_$ServerZone" | Select-Object -ExpandProperty Value
    
  • #65223
    Hil

    Participant
    Points: 23
    Rank: Member

    Thanks Daniel !!!!!
    That was exactly what I was looking for.

The topic ‘Getting the value of a variable’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort