Dynamically creating / evaluating variables

  • I can't remember where I saw this, and can't find it now 🙁

    I want the value of $cTime to be the current value of $Hourly8, namely, 10

    $Hourly8 = 10

    $Hour = 8

    $Var = $($('$Hourly'+$Hour))

    set-Variable -Name cTime -Value $("$var")

    $cTime

    Thanks!

  • May not be what you saw, probably not, but this should do.

    $Hourly8 = 10

    $Hour = 8

    $Var = '$Hourly'+$Hour

    $cTime = Invoke-Expression -Command "$Var"

    $cTime

  • Close enough for rock and roll 😀

    Thanks Bruce!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply