My current goal is to create a function that can produce $ProgressBar1, $ProgressBar2, and so on. While defining the name as such and giving it the appropriate definitions below. Like size and location.
This is for an overly complex Powershell Script w/GUI and I will calling upon a listbox populated with any number of items to a Foreach{MakeBar}. The bars will monitor the task progress.
$counter = 0 is currently defined at the script level.
function MakeBar
{
New-Variable -Name "ProgressBar$script:counter"
ProgressBar$script:counter = New-Object 'System.Windows.Forms.ProgressBar'
$loc = ((23 * $script:counter) + 12)
ProgressBar$script:counter.Location = '94, $loc'
ProgressBar$script:counter.Name = 'progressbar1'
ProgressBar$script:counter.Size = '1109, 23'
ProgressBar$script:counter.TabIndex = 1
$script:counter++
}
I've been warned about modifying things outside of current scope but I am not sure how else or how best to accomplish this in Powershell.
MakeBarshould return aSystem.Windows.Forms.ProgressBarwhich you can store in an array / list instead of using variable counters.$bars = @{'Progress1' = {<#MakeBar#>}; 'Progress2' = {<#MakeBar#>}}