0

I am fairly new with PowerShell New-Object System.Windows.Forms.CheckBox feature.

What I would like to achieve is to create a form with different a dynamic object ( textbox,checkbox,label) The problem comes when I am trying to refer to the checkbox (or any other objects) later on in my code with their respective name. I think I dont use the proper name assignation. I would like the checkbox to be named like the account name so I could refer to it later. ( example: $MyAccountName.Enabled = $false)

$buttonLoadLabels_Click = {
$CheckBoxCounter = 1
$accounts = Get-LocalUser -Name *

foreach ($account in $accounts)
{

    $label=New-Object System.Windows.Forms.Label
    $label.Text=$account
    $label.TextAlign= 'MiddleCenter'
    $label.Font=$label1.Font
    $flowlayoutpanel1.Controls.Add($label)

    $CB = New-Object System.Windows.Forms.CheckBox
    $CB.Name = $account
    $flowlayoutpanel1.Controls.Add($CB)

}

}

Later on the system gives an error when trying to disable the CheckBox stating it is not recognized as a proper Object:

ERROR: The property 'Enabled' cannot be found on this object. Verify that the property exists and can be set.

$MyAccountName.Enabled = $false

Any help is appreciated

Didi
  • 1
  • Where is `$MyAccountName` defined? Please post enough code to reproduce the issue :) – Mathias R. Jessen Oct 30 '19 at 10:52
  • Sorry for confusion. $MyAccountName is what ever account name I have on the local computer. For this example my account name is REPE- so I’m expecting to call my checkbox like this it : $REPE.Enabled= $False – Didi Oct 30 '19 at 11:20
  • Hi heres the new threat if you would like to have a look please, I put a sample code. https://stackoverflow.com/questions/58625486/powershell-studio-dynamic-checkbox-naming-issue – Didi Oct 30 '19 at 12:33

0 Answers0