Is it possible to increment count on variable objects in Powershell?
Example:
$var1 = "This"
$var2 = "Is"
$var3 = "A Test"
1..3 | ForEach-Object {$var$_ = DoSometing}
Reason I am asking this, is because I am creating a GUI with system.Windows.Forms.CheckBox. I have several checkbox objects in variables that end with a number I want to manipulate.
$Checkbox1
$Checkbox2
$Checkbox3
$Checkbox4
I am wondering if there is a clean and good way to manipulate these objects with an Foreach-Object. Instead of manipulating each object seperatly.
$var = 1..3 | ForEach-Object { DoSomething }.New-variablewill help much here. I think for your usecase, you could better loop over the Controls inside your Form object. eg:$Form.Controls. Simply loop over all controls and then check it by name, type or group. Hope it helps!