Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created September 23, 2014 00:51
Show Gist options
  • Select an option

  • Save lantrix/cba5b834020af3f18fc7 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/cba5b834020af3f18fc7 to your computer and use it in GitHub Desktop.
Powershell dynamic variables
$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