Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dynamically creating / evaluating variables Expand / Collapse
Author
Message
Posted Tuesday, April 15, 2014 1:11 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 5:53 AM
Points: 433, Visits: 990
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!



Post #1562030
Posted Tuesday, April 15, 2014 1:56 PM This worked for the OP Answer marked as solution


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 11:44 AM
Points: 60, Visits: 900
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

Post #1562044
Posted Wednesday, April 16, 2014 6:14 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 5:53 AM
Points: 433, Visits: 990
Close enough for rock and roll

Thanks Bruce!



Post #1562254
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse