Scrip - Form to install printers

Hello Everybody

So the rest have eluded me, I need some way to read the contents of the selected drop down list, so I can use it in the install button, have search the web, and I have gotten more confused, so know I try you Gurus :smiley:

Add-Type -AssemblyName


#Set up Default Font

#Set up base form
$AppForm=New-Object $FormObject
$AppForm.Text='Printer Install'

#Building form
$lblPrinters=New-Object $LabelObject
$lblPrinters.Text='PrinterName :'
$lblPrinters.Location=New-Object System.Drawing.Point(20,20)

$ddlPrinters=New-Object $ComboBoxObject
$ddlPrinters.Location=New-Object System.Drawing.Point(140,20)

#load Drop down list
Get-Printer -ComputerName Printserver | ForEach-Object {$ddlPrinters.Items.Add($_.Name)}

$ddlPrinters.Text='Select Printer & Press install'

# Create install button
$Button = New-Object System.Windows.Forms.Button

$Button.Location = New-Object System.Drawing.Size(140,50)

$Button.Size = New-Object System.Drawing.Size(300,50)

$Button.Text = "Install"

#Execute button script


Add-Printer \\printserver\$printqueue


#Add to form

#Show Form


Hi, welcome back :wave:

Use the SelectedItem property.

#Execute button script

$Button.Add_Click ( {
    $printQueue = $ddlPrinters.SelectedItem
    Add-Printer \\printserver\$printQueue
} )

Hi Matt

great, it works, now I just need to find out why the script stalls after printer installation :smiley: is there a way where I can have the button close the form too

Sure, you just add the close method:

$Button.Add_Click ( {
    $printQueue = $ddlPrinters.SelectedItem
    Add-Printer \\printserver\$printQueue
} )