Add groups to active directory with powershell

I have a powershell GUI to create groups in active directory. The GUI looks like this.


The code looks like

#### Form settings ################################################################
$Form                       = New-Object System.Windows.Forms.Form
$Form.FormBorderStyle       = [System.Windows.Forms.FormBorderStyle]::FixedSingle #modifies the window border
$Form.Text                  = "AD GROUP CREATER"
$Form.Size                  = New-Object System.Drawing.Size(750,470)
$Form.StartPosition         = "CenterScreen" #loads the window in the center of the screen
$Form.MinimizeBox           = $False
$Form.MaximizeBox           = $False
$Form.WindowState           = "Normal"
$Form.SizeGripStyle         = "Hide"
$Icon                       = [System.Drawing.Icon]::ExtractAssociatedIcon((Join-Path -Path $PSHOME -ChildPath 'powershell.exe'))
$Form.Icon                  = $Icon



 $options = @{
           Name = $textbox.Text
           GroupScope =            
            GroupCategory = 
            Path = 
        }




#### Label settings #################################################################
$Label           = New-Object System.Windows.Forms.Label
$Label.Location  = New-Object System.Drawing.Size(10,10)
$Label.Size      = New-Object System.Drawing.Size(280,20)
$Label.Text      = "CREATE IN"
$Label.Font      = "8,style=bold"
$Label.Forecolor = "black" 
$Form.Controls.Add($Label) 


#### Group box ########################################################
$groupBox          = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size(10,30)
$groupBox.size     = New-Object System.Drawing.Size(320,50)
$Form.Controls.Add($groupBox)


#### A button ###################################################################
$SPSG          = New-Object System.Windows.Forms.RadioButton
$SPSG.Location = New-Object System.Drawing.Size(15,20)
$spsg.Size     = New-Object System.Drawing.Size(100,20)
$spsg.Text     = "A"
$spsg.Cursor   = [System.Windows.Forms.Cursors]::Hand
$spsg.Add_Click({})
$groupBox.Controls.Add($spsg)


#### B button ###################################################################
$FSG          = New-Object System.Windows.Forms.RadioButton
$FSG.Location = New-Object System.Drawing.Size(150,20)
$Fsg.Size     = New-Object System.Drawing.Size(150,20)
$Fsg.Text     = "B"
$Fsg.Cursor   = [System.Windows.Forms.Cursors]::Hand
$Fsg.Add_Click({})
$groupBox.Controls.Add($Fsg)


#### Label 2 settings #################################################################
$Label2           = New-Object System.Windows.Forms.Label
$Label2.Location  = New-Object System.Drawing.Size(10,100)
$Label2.Size      = New-Object System.Drawing.Size(280,20)
$Label2.Text      = "GROUP NAME"
$label2.Font = "8, style=bold"
$Label2.Forecolor = "black" 
$Form.Controls.Add($Label2) 


#### textbox settings #################################################################
$Textbox          = New-Object System.Windows.Forms.TextBox
$Textbox.Location = New-Object System.Drawing.Size(10,120)
$Textbox.Size     = New-Object System.Drawing.Size(320,20)
$Form.Controls.Add($Textbox)


#### Label 3 settings #################################################################
$Label3           = New-Object System.Windows.Forms.Label
$Label3.Location  = New-Object System.Drawing.Size(10,170)
$Label3.Size      = New-Object System.Drawing.Size(310,20)
$Label3.Text      = "GROUP SECTION"
$Label3.Forecolor = "black" 
$label3.Font = "8, style=bold"
$Form.Controls.Add($Label3) 


#### Group box 2 ########################################################
$groupBox2          = New-Object System.Windows.Forms.GroupBox
$groupBox2.Location = New-Object System.Drawing.Size(10,190)
$groupBox2.size     = New-Object System.Drawing.Size(320,160)
$Form.Controls.Add($groupBox2)


#### local button ###################################################################
$lokal          = New-Object System.Windows.Forms.RadioButton
$lokal.Location = New-Object System.Drawing.Size(15,20)
$lokal.Size     = New-Object System.Drawing.Size(150,20)
$lokal.Text     = "Local"
$lokal.Cursor   = [System.Windows.Forms.Cursors]::Hand
$lokal.Add_Click({})
$groupBox2.Controls.Add($lokal)


#### global button ###################################################################
$global          = New-Object System.Windows.Forms.RadioButton
$global.Location = New-Object System.Drawing.Size(15,70)
$global.Size     = New-Object System.Drawing.Size(150,20)
$global.Text     = "Global"
$global.Cursor   = [System.Windows.Forms.Cursors]::Hand
$global.Add_Click({})
$groupBox2.Controls.Add($global)


#### universal button ###################################################################
$universal          = New-Object System.Windows.Forms.RadioButton
$universal.Location = New-Object System.Drawing.Size(15,120)
$universal.Size     = New-Object System.Drawing.Size(150,20)
$universal.Text     = "Universal"
$universal.Cursor   = [System.Windows.Forms.Cursors]::Hand
$universal.Add_Click({})
$groupBox2.Controls.Add($universal)


#### Label 4 settings #################################################################
$Label4           = New-Object System.Windows.Forms.Label
$Label4.Location  = New-Object System.Drawing.Size(400,170)
$Label4.Size      = New-Object System.Drawing.Size(320,20)
$Label4.Text      = "GROUP TYPE"
$Label4.Forecolor = "black" 
$label4.Font = "8, style=bold"
$Form.Controls.Add($Label4) 


#### Group box 3 ########################################################
$groupBox3          = New-Object System.Windows.Forms.GroupBox
$groupBox3.Location = New-Object System.Drawing.Size(400,190)
$groupBox3.size     = New-Object System.Drawing.Size(320,160)
$Form.Controls.Add($groupBox3)


#### security button ###################################################################
$security          = New-Object System.Windows.Forms.RadioButton
$security.Location = New-Object System.Drawing.Size(15,20)
$security.Size     = New-Object System.Drawing.Size(150,20)
$security.Text     = "Security"
$security.Cursor   = [System.Windows.Forms.Cursors]::Hand
$security.Add_Click({})
$groupBox3.Controls.Add($security)


#### Distribution button ###################################################################
$Distribution          = New-Object System.Windows.Forms.RadioButton
$Distribution.Location = New-Object System.Drawing.Size(15,70)
$Distribution.Size     = New-Object System.Drawing.Size(150,20)
$Distribution.Text     = "Distribution"
$Distribution.Cursor   = [System.Windows.Forms.Cursors]::Hand
$Distribution.Add_Click({})
$groupBox3.Controls.Add($Distribution)


#### Create button ###################################################################
$Create          = New-Object System.Windows.Forms.Button
$Create.Location = New-Object System.Drawing.Size(10,370)
$Create.Text     = "Create"
$Create.Cursor   = [System.Windows.Forms.Cursors]::Hand
$Create.Width     = 710
$Create.Height    = 50
$Create.Font      = "12,style=bold"
$Create.Add_Click({pinginfo})
$Form.Controls.Add($Create)


$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

# destroy the form from memory
$Form.Dispose()


tinytina,
Welcome to the forum. :wave:t4:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

Thanks

https://stackoverflow.com/q/73061301/9196560

And BTW: You forgot to ask a specific question. :wink:

Hi @Olaf
thanks for your reply. Sorry for not providing the link. Doesn’t know that.
My problem is, that i don’t understand, how to combine my selections in the gui to add a code to the create button

You have your form created, but there’s no code behind the buttons.
There should be events assigned to the Create button that would consist of what your code is actually doing behind the Create button.

The form looks good, but you need the functionality of the click event added.

You seem to already be processing the Button Click event by calling a “pinginfo” function, you would reference back to the properties of other controls on the form to define the actions you need to take. Some pseudo code …

if($Security.Checked)  {
  Do_Something
}

Some google search options

“windows forms radio button properties”
“windows forms text box properties”

You will need to use these properties to define the criteria for your group creation.

can someone help me writing down the code. doesn’t know how to create that with my decisions i made in the gui

yes thats my problem. i don’t know how to add the code with i clicks i have choosen in my gui