Created
September 23, 2014 00:51
-
-
Save lantrix/cba5b834020af3f18fc7 to your computer and use it in GitHub Desktop.
Powershell dynamic variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $varsToSet = @("Something","Else","Here") | |
| $i=0 | |
| #set variables | |
| foreach ($this in $varsToSet) { | |
| $i++ | |
| New-Variable -Name "dynamic$($this)" -Value $i | |
| } | |
| #retrieve variables | |
| $varsToSet | % { | |
| #Dynamic variables for value of each tag to retrieve | |
| Get-Variable -Name "dynamic$($_)" -ValueOnly | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment