I'm not entirely sure how to word this so bare with me. The orginization i work for is taking away a license for a software we use to connect to our network switches using a basic SSH connection. Just using PowerShell i know this command works for us. ssh username#IP_of_Switch now comes the fun part.
I want to make a GUI for our techs so they just have to select the switch name and not have to know every IP of all 100+ switches. I know for a drop down box it would look like this
$DropDownBox = New-Object System.Windows.Forms.ComboBox
$DropDownBox.Location = New-Object System.Drawing.Size(20,50)
$DropDownBox.Size = New-Object System.Drawing.Size(180,20)
$DropDownBox.DropDownHeight = 200
$Form.Controls.Add($DropDownBox)
$swList=#("1D","3D","3F","6E","Laundry","Chapel")
foreach ($sws in $swList) {$DropDownBox.Items.Add($sw)} #end foreach
What i want to do is have those Names be associated with their respective IP some how. AND HAVE A BUTTON TO CONNECT THEM TO SELECTED SWITCHI have a slight idea that i may need to have a txt file with the IP's. Any help would be greatly appreciated.
ComboBox is inherited from ListControl
You should provide Objects to ListItems. Each object should contain at least 2 properties: displayName and value ( you can change names of properties how you want ).
You need to set ComboBox's properties DisplayMember to name of property should be displayed.
Example:
In $FormEvent_Load scriptblock, we add items to ComboBox. Those items are objects with (at least) 2 properties - Name and Address. There we also set DisplayMember property of ComboBox to let it know, which property should be displayed in UI.
In $CBEvent_SelectedIndexChanged scriptblock, we get SelectedItem property from ComboiBox. SelectedItem contains original object we passed to ComboBox.Items.Add. There is Address field as you see, which can be used.
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$form1 = New-Object System.Windows.Forms.Form
$combobox1 = New-Object System.Windows.Forms.ComboBox
$label1 = New-Object System.Windows.Forms.Label
$FormEvent_Load = {
$combobox1.DisplayMember = 'Name'
$combobox1.Items.Add(
[PSCustomObject]#{
'Name' = 'Switch1'
'Address' = [ipaddress]::Parse('1.1.1.1')
})
$combobox1.Items.Add(
[PSCustomObject]#{
'Name' = 'Switch2'
'Address' = [ipaddress]::Parse('2.12.21.22')
})
}
$CBEvent_SelectedIndexChanged = {
$label1.Text = $combobox1.SelectedItem.Address.ToString()
}
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 292
$System_Drawing_Size.Height = 266
$form1.ClientSize = $System_Drawing_Size
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 83
$System_Drawing_Point.Y = 199
$label1.Location = $System_Drawing_Point
$label1.Text = 'Select IP'
$form1.Controls.Add($label1)
$form1.Controls.Add($combobox1)
$form1.add_Load($FormEvent_Load)
$ComboBox1.add_SelectedIndexChanged($CBEvent_SelectedIndexChanged)
$form1.ShowDialog()| Out-Null
This is just an example but it does work. I used a simple csv file to hold the switch IP Addresses. I edited an answer for the majority of this script so I will give credit for that Powershell default dropdown value
CSV File
1D,127.0.0.1
3D,127.0.0.2
3F,127.0.0.3
6E,127.0.0.4
Laundry,127.0.0.5
Chapel,127.0.0.6
Script
########################
# Edit This item to change the DropDown Values
$switchesFilePath = "C:\temp\switches.csv"
$switches = ConvertFrom-Csv (Get-Content -Path $switchesFilePath)
# This Function Returns the Selected Value and Closes the Form
function Return-DropDown {
$script:Choice = $DropDown.SelectedItem
Write-Host "The selected switch is $($script:Choice.Name) and it's IP is $($script:Choice.IPAddress)"
Write-Host "The ssh command would be ---- ssh username#$($script:Choice.IPAddress)"
$Form.Close()
}
function selectSwitch{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$Form = New-Object System.Windows.Forms.Form
$Form.width = 300
$Form.height = 150
$Form.Text = ”DropDown”
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(130,30)
$DropDown.SelectedItem = $DropDown.Items[0]
$DropDown.DisplayMember = 'Name'
[void] $DropDown.Items.AddRange($switches)
$Form.Controls.Add($DropDown)
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,40)
$DropDownLabel.Text = "Select a network switch"
$Form.Controls.Add($DropDownLabel)
$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(100,50)
$Button.Size = new-object System.Drawing.Size(100,20)
$Button.Text = "Connect to a switch"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
return $script:choice
}
$switch = selectSwitch
I am working on a script and am stuck at an error I am getting. I wanted to see if anyone could point me in the right direction. Basically I want a user to search AD and generate a report in.CSV file of the users in a particular group. I will show the script and the error below. Any advice would be most welcome. I know it can be done better and cleaned up but for now, it works.
<#
.NOTES
===========================================================================
Created with: PowerShell
Created on: 6/8/2020 3:51 PM
Created by: William Christner
Organization: BCBSA
Filename: AD Group Report
===========================================================================
.DESCRIPTION
Search AD groups, create a .CSV report of users in the group.
#>
####################################################################
import-module ActiveDirectory
####################################################################
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Select AD Group'
$form.Size = New-Object System.Drawing.Size(350, 140)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(125, 50)
$okButton.Size = New-Object System.Drawing.Size(75, 23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$okButton.add_Click({
######################################################################################################
$GroupName = "$textBox"
$Date = Get-Date -UFormat "%m.%d.%y_%H.%M"
$Members = Get-ADGroupMember -Identity $GroupName -Recursive | Select -ExpandProperty SAMAccountName
Foreach ($Name in $Members) {
Get-ADUser $Name -properties * | Select EmailAddress,SAMAccountName,DisplayName,OfficePhone,CanonicalName,Enabled |
Export-Csv -append C:\Reports\$($GroupName)_Membership_Detailed_$($Date).csv -NoTypeInformation -Encoding UTF8 }
})
#####################################################################################################################
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(225, 50)
$cancelButton.Size = New-Object System.Drawing.Size(75, 23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.Size = New-Object System.Drawing.Size(130, 20)
$label.Text = 'Please select AD Group:'
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(150, 15)
$textBox.Size = New-Object System.Drawing.Size(150, 40)
$form.Controls.Add($textBox)
$textbox.AutoCompleteSource = 'CustomSource'
$textbox.AutoCompleteMode = 'SuggestAppend'
$textbox.AutoCompleteCustomSource = $autocomplete
"awsarchitect",
"BHI",
"cc_support",
"Citrix",
"CyberArk",
"CyberArk_Admins",
"Datastage",
"DB2DBA",
"Distribution Groups",
"DS_Core_Security",
"DS_FEPSIU",
"ems-test",
"FAS_COLDFUSION_DEV",
"FEPBlue",
"FEPOC_MousePointer",
"FogOperations",
"GG_AcceletestAdmins",
"GG_AcceletestUsers",
"GG_Allow LinkedIn",
"GG_Allow_AWS",
"GG_Allow_Firewall_ERwin",
"GG_Allow_Firewall_Hyper-V",
"GG_Allow_Firewall_IBM_Websphere",
"GG_Allow_Firewall_Loadrunner",
"GG_Allow_Firewall_Mainframe",
"GG_Allow_Firewall_NEBA_FTP",
"GG_Allow_Firewall_nodejs",
"GG_Allow_Firewall_Observer_Platform",
"GG_Allow_Firewall_R_Selenium",
"GG_Allow_Firewall_Safeend_DPA",
"GG_Allow_Firewall_SoapUI",
"GG_Allow_Lockdown",
"GG_Allow_MS_Collab_Sites",
"GG_Allow_Skype",
"GG_Allow_Website_Menshealth",
"GG_Allow_Windows_GINA",
"GG_Allow_Wireless",
"GG_Ansible_Development",
"GG_ApplicationSupport_Users",
"gg_bcbsa_sp_audit",
"GG_BindAccounts",
"GG_Blackberry_SSP",
"GG_Chrome_NoPolicies",
"GG_Clearwell_Admin",
"GG_Container_Admins_Nonprod",
"GG_ContentDistributor",
"GG_Contingent",
"GG_Core_GPO",
"GG_Core_GPO_POC",
"GG_Core_Mid",
"GG_CredSSP_Vuln",
"GG_CTX_Allow_Shadow",
"GG_DEP_Disabled",
"GG_DevFep",
"GG_DriveMappings_Test_Group",
"GG_Dropbox ",
"GG_DUOAlerts",
"GG_eDiscovery_Collections",
"GG_EMS_Files",
"GG_EV_Client11_Pilot",
"GG_EV_Phase2_Pilot",
"GG_Exchange_CalendarAdmins",
"GG_Exchange_ISAdmin",
"GG_Exchange_JrAdmin",
"GG_Exchange_MidAdmin",
"GG_Exchange_PowerShell",
"GG_Exchange_SrAdmin",
"GG_Exchange_Training",
"GG_Extend_ScreenSaver",
"gg_fep_contingents",
"GG_FEP_PS_Admins",
"GG_FEP_SIU",
"GG_FEP_SIU_Legal",
"gg_fep_sr_staff",
"gg_fep_staff",
"GG_Firewall_Testing",
"GG_Firewall_Triage",
"GG_Foglight_Read",
"GG_Git-Admins",
"GG_Git-Users",
"GG_Google_Man",
"GG_Google_SU",
"GG_GPO-Arch",
"GG_IBC_SandBox",
"GG_IDN_Pilot",
"GG_Infosys",
"GG_iSight-SRM",
"GG_JumpServers",
"GG_L4CERT_Administrators",
"GG_Legal_Hold",
"GG_Legal_Hold_Pilot",
"GG_LocalProfileRedirect_CHG",
"GG_LocalProfileRedirect_MDC",
"GG_Lost_Devices",
"GG_LTDMailbox",
"GG_Microsoft_Patch_Alerts",
"GG_Mobile_Users_CHG",
"GG_Mobile_Users_Execs",
"GG_Mobile_Users_MDC",
"GG_MSP_Infosys",
"GG_MSP_TechMahindra",
"GG_MSP_UST",
"GG_No_WPAD",
"GG_NRS_Extracts_Access",
"GG_O365_Migration",
"GG_OneDrive_Pilot",
"GG_PeopleSoft_Testers",
"GG_Proxy_WPAD2",
"GG_RDM_ADMIN_NP",
"GG_RDM_Admin_p",
"GG_RDM_ALL",
"GG_RDM_APP_NP",
"GG_RDM_BDC",
"GG_RDM_BLUE2",
"GG_RDM_IPDS",
"GG_RDM_ITS",
"GG_RDM_LDLA",
"GG_RDM_PDSU",
"GG_RDM_TREATMENT_CATEGORY",
"GG_RDM_USER_NP",
"GG_RDM_User_p",
"GG_RDM_WEB_SERVICES",
"GG_RDP_Users ",
"GG_RecordPoint365_Admins",
"GG_Remove_ScreenSaver",
"GG_RMS_SuperUsers",
"GG_Screensaver_Blank",
"GG_Screensaver_Presentations",
"GG_Screensaver_Windows10_Lockscreen",
"GG_SIEM_Log_Captures",
"GG_SIEM_Log_Captures_CHG",
"GG_SIEM_Log_Captures_MDC",
"GG_SIEM_Log_Captures_NGS",
"GG_SIEM_Log_Captures_Rollback",
"GG_StaffNow",
"GG_StateAffairs",
"GG_Tableau_Admin ",
"GG_UC_VMware_Admin",
"GG_VDI_Application_Permissions",
"GG_VDI_PEOPLESOFT_REPORTING-FEPprd",
"GG_VDIDesktopSupport",
"GG_Web_Servers",
"GG_WebEx_Users",
"GG_Windows10_GPO_Testing",
"GG_Windows10_Users",
"GG_Wireless_Profile_Testers",
"GG_Wireless_Testers",
"HPE_IRS",
"Hyperion-Users",
"HyperV_Servers",
"Informatica",
"JohnsAwesomeGPOTestingGroup",
"mongo_nw_pe",
"mongo_rw_dev",
"mongo_rw_pv",
"NetApp",
"NoOutlookNoIE",
"NOW_Upgrade_Temp12",
"O365",
"OKTA",
"Projects",
"QualityStage",
"sco",
"SCOM",
"SCVMM",
"SNOW_Upgrade_Temp_test",
"SNOW_Upgrade_Temp11",
"SNOW_Upgrade_Temp12",
"SNOW_Upgrade_Temp123",
"SNOW_Upgrade_Temp1256",
"SNOW_Upgrade_Temp132",
"SNOW_Upgrade_Temp145",
"SNOW_Upgrade_Temp2",
"SNOW_Upgrade_Temp3",
"SNOW_Upgrade_Temp33",
"SNOW_Upgrade_Temp444",
"SNOW_Upgrade_Temp555",
"SNOW_Upgrade_Temp888",
"Specopshe",
"SUG_FlashPlayerPilot",
"SystemCenter",
"Tower",
"UCSD",
"VCO-Admin",
"VMware"| % { $textbox.AutoCompleteCustomSource.AddRange($_) }
#[void]$listBox.Items.Add('atl-dc-001')
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $listBox.SelectedItem
$x
}
The error I am getting is as follows:
Looks like it is not seeing the Group in the Domain however when I run the same script it dose work by itself and created the report. I am thinking there is something missing from the textbox input and the rest of the script.
Thanks again for taking a look.
Cheers
You'll want to grab the textbox value from it's Text property:
$GroupName = $textBox.Text
I would like to have a tech enter in the username and the group name but in one input box. Anyone willing to tell me how to do this?
Function add-togroup{
#Adds members to group in AD
#$users = Read-Host "Enter a username"
Add-Type -AssemblyName Microsoft.VisualBasic;
$value = [Microsoft.VisualBasic.Interaction]::InputBox('Enter username',
'Username')
$value2 = [Microsoft.VisualBasic.Interaction]::InputBox('Enter group
name', 'XA Group','')
$group_membership = Get-ADPrincipalGroupMembership $users | select name |
format-table -auto
foreach($u in $value)
{
Add-ADGroupMember $value2 -Members $u
}
Write-Host $group_membership
}
So I am capable of using multiple dialogs in sequence but it would make for a better user experience if I could roll this into one single box /form.
If you are not satisfied with the basic forms available then one option you have is to roll your own in PowerShell with .Net forms. Just to show an example that you can build from...
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({
if ($_.KeyCode -eq "Enter" -or $_.KeyCode -eq "Escape"){
$objForm.Close()
}
})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the information in the space below:"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,70)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void]$objForm.ShowDialog()
$objTextBox.Text
$objTextBox2.Text
The borrows heavily from the great primer on the subject on TechNet which you should read as it walks you though this better. I removed some of the variable population logic as it was flawed and added another text box. The last two lines return the values entered by the "user". Aside from the addition of the text box I have left most other cosmetic changes up to you to help you get a better understanding of what is involved here.
Keep in mind the locations and sizes of newly added objects and be sure you actually add it to the form.
Since there is not GUI for form building it can seem daunting but its not really that hard to do. You just need to experiment. If you are so inclined there are 3rd party tools that will help with that.
im creating a gui script for users to get certain files, its not finished yet but i have a problem i cant solve.
i want to have choices of which file they want + an option for them to insert a name that they want for the file that they chose.
the problem is the text box is cut in the middle and only if you write a lot you will see the end of your text.
please help! thanks a lot!
this is the full script: *again-not complete
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#This creates the path for the Json and also check if it is already there.
If(!(Test-Path -Path C:\Users\$env:USERNAME\documents\Json))
{
New-Item c:\users\$env:USERNAME\documents -ItemType directory -Name Json
$path = "c:\users\$env:USERNAME\documents\Json"
}
#creating the form
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Ofir`s script"
$objForm.Size = New-Object System.Drawing.Size(480,200)
$objForm.StartPosition = "CenterScreen"
#creating the label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(20,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please check the relevant boxes:"
$objForm.Controls.Add($objLabel)
#This creates a checkbox called dsp.z
$objDspCheckbox = New-Object System.Windows.Forms.Checkbox
$objDspCheckbox.Location = New-Object System.Drawing.Size(20,40)
$objDspCheckbox.Size = New-Object System.Drawing.Size(280,20)
$objDspCheckbox.Text = "dsp.z"
$objDspCheckbox.TabIndex = 0
$objForm.Controls.Add($objDspCheckbox)
#This creates a checkbox called fpga.bin
$objFpgaCheckbox = New-Object System.Windows.Forms.Checkbox
$objFpgaCheckbox.Location = New-Object System.Drawing.Size(20,60)
$objFpgaCheckbox.Size = New-Object System.Drawing.Size(280,20)
$objFpgaCheckbox.Text = "fpga.bin"
$objFpgaCheckbox.TabIndex = 1
$objForm.Controls.Add($objFpgaCheckbox)
#This creates a checkbox called bootrom_uncmp.bin
$objBootCheckbox = New-Object System.Windows.Forms.Checkbox
$objBootCheckbox.Location = New-Object System.Drawing.Size(20,80)
$objBootCheckbox.Size = New-Object System.Drawing.Size(280,20)
$objBootCheckbox.Text = "bootrom_uncmp.bin"
$objBootCheckbox.TabIndex = 2
$objForm.Controls.Add($objBootCheckbox)
#This creates a label for the TextBox1
$objLabel1 = New-Object System.Windows.Forms.Label
$objLabel1.Location = New-Object System.Drawing.Size(300,20)
$objLabel1.Size = New-Object System.Drawing.Size(280,20)
$objLabel1.Text = "Change the name?:"
$objForm.Controls.Add($objLabel1)
#This creates the TextBox1
$objTextBox1 = New-Object System.Windows.Forms.TextBox
$objTextBox1.Location = New-Object System.Drawing.Size(200,40)
$objTextBox1.Size = New-Object System.Drawing.Size(200,20)
$objTextBox1.TabIndex = 3
$objForm.Controls.Add($objTextBox1)
#ok Button
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(40,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click(
{
if ($objDspCheckbox.Checked -eq $true)
{
New-Item $path -itemtype file -name Dsp.json -value #"
"{"sys_ver":"01.01.01.02","RED":[],"RED_VA":[],"BLACK": [{"type":"6","type_descr":"DSP file","tar_name":"dsp.tar.gz","image_name":"dsp.z","CRC":"1234567","version":"01.01.01.02","metadata":"62056"}
],"BLACK_VA":[]
}"
"# ;$objForm.close()
}
elseif ($objFpgaCheckbox.Checked -eq $true)
{
New-Item $path -itemtype file -name Fpga.json -value #"
"
{"type":"4","type_descr":"FPGA file","tar_name":"FPGA.tar.gz","image_name":"fpga.z","CRC":"1234567","version":"01.01.01.02","metadata":"9730652"},
"
"#
;$objForm.close()
}
elseif ($objBootCheckbox.Checked -eq $true)
{
New-Item $path -itemtype file -name Boot.json -value "Hello3" ;$objForm.close()
}
})
$objForm.Controls.Add($OKButton)
#cancle Button
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(140,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
#Parameters (Need to add)
$dspname = $objTextBox1
#makes the form appear on top of the screen
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
the problem is the text box is cut in the middle and only if you write a lot you will see the end of your text. please help! thanks a lot!
The problem is that the TextBox control is hidden underneath your CheckBox controls, because you've configured them to be ridiculously wide.
Change:
$objDspCheckbox.Size = New-Object System.Drawing.Size(280,20)
to something more sensible, like 150px instead of 280px:
$objDspCheckbox.Size = New-Object System.Drawing.Size(150,20)
Do this for all the checkboxes and you'll find the problem goes away.
Alternatively, bring the $objTextBox1 control to the front by setting a ChildIndex of 0 on it's parent (the Form object itself):
$objForm.Controls.SetChildIndex($objTextBox1,0)
after adding all child controls (but before calling $objForm.ShowDialog())