Powershell GUI – Adding bells and whistles

In my previous post “Getting your feet wet with Powershell GUI” I had mentioned how difficult it was get a concise documentation on creating Powershell GUI. To my surprise I discovered that there is a real cool tool developed by Sapien Technologies that allows you to create a Powershell GUI. They have a free Powershell Form creator – Primal Forms Community Creator” which enables you to create a nifty GUI. I was able to create a neat Form and then fill in the details of actually manipulating the controls I added. For details about the controls of a textBox, comboBox etc in Powershell refer to the MSDN library. This was the Powershell GUI I had created.

I have included the code below to execute some basic commands

Note: You can clone the code below from GitHub : Creating a GUI in powershell

#########################################################################################################
# Developed by Tinniam V Ganesh
# Date 24 Apr 2012
# Powershell GUI generated by Primal Forms CE from Sapien Technologies (http://www.sapien.com/)
#########################################################################################################
function Get-SysInfo ($strComputer)
{
write-host “reached here”
$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_ComputerSystem -Namespace “root\CIMV2″ -ComputerName $strComputer|Export-csv -force “test.csv”
}
else
{
$wmi =Get-WmiObject Win32_ComputerSystem -Namespace “root\CIMV2″ -ComputerName $strComputer|ConvertTo-Html|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

#*=============================================================================
Function Get-BIOSInfo ($strComputer)
{
$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_BIOS -Namespace “root\CIMV2″ -computername $strComputer|Export-csv -force “test.csv”
}
else
{
$wmi = Get-WmiObject Win32_BIOS -Namespace “root\CIMV2″ -computername $strComputer|ConvertTo-Html|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

Function Get-OSInfo {
$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_OperatingSystem -Namespace “root\CIMV2″ -Computername $strComputer|Export-csv -force “test.csv”
}
else
{
$wmi = Get-WmiObject Win32_OperatingSystem -Namespace “root\CIMV2″ -Computername $strComputer|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

Function Get-CPUInfo {

$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_Processor -Namespace “root\CIMV2″ -Computername $strComputer|Export-csv -force “test.csv”
}
else
{
$wmi = Get-WmiObject Win32_Processor -Namespace “root\CIMV2″ -Computername $strComputer|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

Function Get-DiskInfo {

$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_DiskDrive -Namespace “root\CIMV2″ -ComputerName $strComputer|Export-csv -force “test.csv”
}
else
{
$wmi = Get-WmiObject Win32_DiskDrive -Namespace “root\CIMV2″ -ComputerName $strComputer|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

Function Get-NetworkInfo {

$statusBar1.Text =”Working …”
if ($radiobutton1.checked -eq $True)
{
$wmi = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace “root\CIMV2″ -ComputerName $strComputer | where{$_.IPEnabled -eq “True”}|Export-csv -noclobber “test.csv”
}
else
{
$wmi = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace “root\CIMV2″ -ComputerName $strComputer | where{$_.IPEnabled -eq “True”}|out-file -append “test.html”
}

$statusBar1.Text =”Done.”
}

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 4/24/2012 2:46 PM
# Generated By: tvganesh
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
[reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$statusBar1 = New-Object System.Windows.Forms.StatusBar
$label2 = New-Object System.Windows.Forms.Label
$button3 = New-Object System.Windows.Forms.Button
$button2 = New-Object System.Windows.Forms.Button
$tabControl1 = New-Object System.Windows.Forms.TabControl
$tabControl = New-Object System.Windows.Forms.TabPage
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$radioButton2 = New-Object System.Windows.Forms.RadioButton
$radioButton1 = New-Object System.Windows.Forms.RadioButton
$label1 = New-Object System.Windows.Forms.Label
$textBox1 = New-Object System.Windows.Forms.TextBox
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$Database = New-Object System.Windows.Forms.TabPage
$tabPage1 = New-Object System.Windows.Forms.TabPage
$tabPage2 = New-Object System.Windows.Forms.TabPage
$button1 = New-Object System.Windows.Forms.Button
$fontDialog1 = New-Object System.Windows.Forms.FontDialog
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#———————————————-
#Generated Event Script Blocks
#———————————————-
#Provide Custom Code for events specified in PrimalForms.
$button3_OnClick=
{
$form1.Close()

}

$button2_OnClick=
{
$textBox1.text=””
# Set to the first item
$comboBox1.SelectedIndex = 0;

}

$handler_button1_Click=
{
$x = $textbox1.text
$vals = $x.split(“,”)
forEach($strComputer in $vals)
{
switch($combobox1.selectedItem)
{
“SysInfo” {Get-SysInfo ($strComputer)}
“BiosInfo” {Get-BiosInfo($strComputer)}
“CPUInfo” {Get-cpuInfo($strComputer)}
“DiskInfo” {Get-diskInfo($strComputer)}
“OSInfo” {Get-OSInfo($strCOmputer)}
“NetworkInfo” {Get-NetworkInfo($strComputer)}
}
}
}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}

#———————————————-
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 444
$System_Drawing_Size.Width = 704
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = “form1”
$form1.Text = “Primal Form”

$statusBar1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 422
$statusBar1.Location = $System_Drawing_Point
$statusBar1.Name = “statusBar1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 704
$statusBar1.Size = $System_Drawing_Size
$statusBar1.TabIndex = 8
$statusBar1.Text = “Ready”

$form1.Controls.Add($statusBar1)

$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Font = New-Object System.Drawing.Font(“Microsoft Sans Serif”,14.25,1,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 205
$System_Drawing_Point.Y = 22
$label2.Location = $System_Drawing_Point
$label2.Name = “label2”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 34
$System_Drawing_Size.Width = 341
$label2.Size = $System_Drawing_Size
$label2.TabIndex = 7
$label2.Text = “Windows Resource Management”

$form1.Controls.Add($label2)
$button3.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 439
$System_Drawing_Point.Y = 343
$button3.Location = $System_Drawing_Point
$button3.Name = “button3”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button3.Size = $System_Drawing_Size
$button3.TabIndex = 6
$button3.Text = “Exit”
$button3.UseVisualStyleBackColor = $True
$button3.add_Click($button3_OnClick)

$form1.Controls.Add($button3)
$button2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 330
$System_Drawing_Point.Y = 343
$button2.Location = $System_Drawing_Point
$button2.Name = “button2”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button2.Size = $System_Drawing_Size
$button2.TabIndex = 5
$button2.Text = “Cancel”
$button2.UseVisualStyleBackColor = $True
$button2.add_Click($button2_OnClick)

$form1.Controls.Add($button2)

$tabControl1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 136
$System_Drawing_Point.Y = 83
$tabControl1.Location = $System_Drawing_Point
$tabControl1.Name = “tabControl1”
$tabControl1.SelectedIndex = 0
$tabControl1.ShowToolTips = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 231
$System_Drawing_Size.Width = 453
$tabControl1.Size = $System_Drawing_Size
$tabControl1.TabIndex = 4

$form1.Controls.Add($tabControl1)
$tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$tabControl.Location = $System_Drawing_Point
$tabControl.Name = “tabControl”
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$tabControl.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 205
$System_Drawing_Size.Width = 445
$tabControl.Size = $System_Drawing_Size
$tabControl.TabIndex = 0
$tabControl.Text = “Basic Commands”
$tabControl.UseVisualStyleBackColor = $True

$tabControl1.Controls.Add($tabControl)

$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 271
$System_Drawing_Point.Y = 123
$groupBox1.Location = $System_Drawing_Point
$groupBox1.Name = “groupBox1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 49
$System_Drawing_Size.Width = 124
$groupBox1.Size = $System_Drawing_Size
$groupBox1.TabIndex = 3
$groupBox1.TabStop = $False
$groupBox1.Text = “Save As”

$tabControl.Controls.Add($groupBox1)

$radioButton2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 48
$System_Drawing_Point.Y = 19
$radioButton2.Location = $System_Drawing_Point
$radioButton2.Name = “radioButton2”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 24
$System_Drawing_Size.Width = 104
$radioButton2.Size = $System_Drawing_Size
$radioButton2.TabIndex = 1
$radioButton2.TabStop = $True
$radioButton2.Text = “HTML”
$radioButton2.UseVisualStyleBackColor = $True

$groupBox1.Controls.Add($radioButton2)
$radioButton1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 6
$System_Drawing_Point.Y = 19
$radioButton1.Location = $System_Drawing_Point
$radioButton1.Name = “radioButton1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 24
$System_Drawing_Size.Width = 104
$radioButton1.Size = $System_Drawing_Size
$radioButton1.TabIndex = 0
$radioButton1.TabStop = $True
$radioButton1.Text = “CSV”
$radioButton1.UseVisualStyleBackColor = $True
$radioButton1.checked =$True

$groupBox1.Controls.Add($radioButton1)
$label1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 6
$System_Drawing_Point.Y = 26
$label1.Location = $System_Drawing_Point
$label1.Name = “label1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 192
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 2
$label1.Text = “Enter comma separated server list”

$tabControl.Controls.Add($label1)

$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 220
$System_Drawing_Point.Y = 26
$textBox1.Location = $System_Drawing_Point
$textBox1.Name = “textBox1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 203
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 1

$tabControl.Controls.Add($textBox1)

$comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox1.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 220
$System_Drawing_Point.Y = 79
$comboBox1.Location = $System_Drawing_Point
$comboBox1.Name = “comboBox1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 21
$System_Drawing_Size.Width = 200
$comboBox1.Size = $System_Drawing_Size
$comboBox1.TabIndex = 0

$commands = @(“SysInfo”,”BIOSInfo”,”OSInfo”,”CPUInfo”,”DiskInfo”,”NetworkInfo”)
ForEach ($command in $commands){
$comboBox1.items.add($command)
}
$tabControl.Controls.Add($comboBox1)

# Set to the first item
$comboBox1.SelectedIndex = 0;
$Database.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$Database.Location = $System_Drawing_Point
$Database.Name = “Database”
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$Database.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 205
$System_Drawing_Size.Width = 445
$Database.Size = $System_Drawing_Size
$Database.TabIndex = 1
$Database.Text = “Database”
$Database.UseVisualStyleBackColor = $True

$tabControl1.Controls.Add($Database)

$tabPage1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$tabPage1.Location = $System_Drawing_Point
$tabPage1.Name = “tabPage1”
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$tabPage1.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 205
$System_Drawing_Size.Width = 445
$tabPage1.Size = $System_Drawing_Size
$tabPage1.TabIndex = 2
$tabPage1.Text = “Active Directory”
$tabPage1.UseVisualStyleBackColor = $True

$tabControl1.Controls.Add($tabPage1)

$tabPage2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$tabPage2.Location = $System_Drawing_Point
$tabPage2.Name = “tabPage2”
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$tabPage2.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 205
$System_Drawing_Size.Width = 445
$tabPage2.Size = $System_Drawing_Size
$tabPage2.TabIndex = 3
$tabPage2.Text = “Backup & Restore”
$tabPage2.UseVisualStyleBackColor = $True

$tabControl1.Controls.Add($tabPage2)

$button1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 226
$System_Drawing_Point.Y = 343
$button1.Location = $System_Drawing_Point
$button1.Name = “button1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 0
$button1.Text = “Submit”
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($handler_button1_Click)

$form1.Controls.Add($button1)

$fontDialog1.ShowHelp = $True

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Related posts
1. Stir fry a VBA application quickly
2.Building a respectable VBA with Excel application
3. Get your feet wet with Powershell GUI
4. Powershell GUI – Adding bells and whistles
5. Slicing and dicing with LogParser & VBA
6. Adventures in LogParser, HTA and charts.

Also see
Brewing a potion with Bluemix, PostgreSQL, Node.js in the cloud
A Bluemix recipe with MongoDB and Node.js A Cloud medley with IBM Bluemix, Cloudant DB and Node.js
– A crime map of India in R: Crimes against women
– What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress – Part 1
– Bend it like Bluemix, MongoDB with autoscaling – Part 1
– Analyzing cricket’s batting legends – Through the mirage with R
– Masters of spin: Unraveling the web with R

 

Find me on Google+

Get your feet wet with Powershell GUI

Here’s my latest attempt in creating a simple GUI using Powershell for Windows Resource Management Tasks. Powershell by itself is easy but there is hardly any documentation on the web for creating a cool GUI. You have to put together various bits and pieces by the trial and error method. Anyway I did come up with some success. However there is a lot to be desired. For some reason the results only show up when the GUI is closed through the Cancel or Exit button. Feel free to tweak the code as you please. The Windows Management Commands are some basic scripts taken from Powershell Pro.

This is the GUI I created. Do read my post Powershell GUI – Adding bells & whistles for creating a full-fledged Powershell GUI

Feel free to send me any comments.

[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

# Add functions
#*=============================================================================
Function BIOSInfo {
$colItems = Get-WmiObject Win32_BIOS -Namespace “root\CIMV2″ -computername $strComputer
foreach($objItem in $colItems) {
“—————————— Bios Info ———————”
“Computer Name: “+ $strComputer
“BIOS Characteristics: “+ $objItem.BiosCharacteristics
“BIOS Version: “+ $objItem.BIOSVersion
“Build Number: “+ $objItem.BuildNumber
“Caption: “+ $objItem.Caption
“Code Set: “+ $objItem.CodeSet
“Current Language: “+ $objItem.CurrentLanguage
“Description: “+ $objItem.Description
“Identification Code: “+ $objItem.IdentificationCode
“Installable Languages: “+ $objItem.InstallableLanguages
“Installation Date: “+ $objItem.InstallDate
“Language Edition: “+ $objItem.LanguageEdition
“List Of Languages: “+ $objItem.ListOfLanguages
“Manufacturer: “+ $objItem.Manufacturer
“Name: ” + $objItem.Name
“Other Target Operating System: “+ $objItem.OtherTargetOS
“Primary BIOS: “+ $objItem.PrimaryBIOS
“Release Date: “+ $objItem.ReleaseDate
“Serial Number: “+ $objItem.SerialNumber
“SMBIOS BIOS Version: “+ $objItem.SMBIOSBIOSVersion
“SMBIOS Major Version: “+ $objItem.SMBIOSMajorVersion
“SMBIOS Minor Version: “+ $objItem.SMBIOSMinorVersion
“SMBIOS Present: “+ $objItem.SMBIOSPresent
“Software Element ID: “+ $objItem.SoftwareElementID
“Software Element State: “+ $objItem.SoftwareElementState
“Status: “+ $objItem.Status
“Target Operating System: “+ $objItem.TargetOperatingSystem
“Version: “+ $objItem.Version

}
}

Function OSInfo {
$colItems = Get-WmiObject Win32_OperatingSystem -Namespace “root\CIMV2” -Computername $strComputer
foreach($objItem in $colItems) {
“—————————— OS Info ———————”
“Computer Name: “+ $strComputer
“Operating System:” + $objItem.Name
}
}

Function CPUInfo {
$colItems = Get-WmiObject Win32_Processor -Namespace “root\CIMV2” -Computername $strComputer
foreach($objItem in $colItems) {
“————————CPU Info ————————-”
“Computer Name: “+ $strComputer
“Caption: ”+ $objItem.Caption
“CPU Status: ”+ $objItem.CpuStatus
“Current Clock Speed: ”+ $objItem.CurrentClockSpeed
“Device ID: ”+ $objItem.DeviceID
“L2 Cache Size: ”+ $objItem.L2CacheSize
“L2 Cache Speed: ”+ $objItem.L2CacheSpeed
“Name: ”+ $objItem.Name
“System Name:” + $objItem.SystemName

}
}

Function DiskInfo {
$colItems = Get-WmiObject Win32_DiskDrive -Namespace “root\CIMV2″ -ComputerName $strComputer
foreach($objItem in $colItems) {
“————————- Disk Info ——————–”
“Computer Name: “+ $strComputer
“Description: ”+ $objItem.Description
“Device ID: ”+ $objItem.DeviceID
“Interface Type: ”+ $objItem.InterfaceType
“Media Type: ”+ $objItem.MediaType
“Model: ”+ $objItem.Model
“Partitions: ”+ $objItem.Partitions
“Size: ”+ $objItem.Size
“Status: ”+ $objItem.Status

}
}

Function NetworkInfo {
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace “root\CIMV2” -ComputerName $strComputer | where{$_.IPEnabled -eq “True”}
foreach($objItem in $colItems) {
“—————————— Network Info ———————”
“Computer Name: “+ $strComputer
“DHCP Enabled:” + $objItem.DHCPEnabled
“IP Address:” + $objItem.IPAddress
“Subnet Mask:” + $objItem.IPSubnet
“Gateway:” + $objItem.DefaultIPGateway
“MAC Address:” + $ojbItem.MACAddress
}
}
Function SysInfo {

$colItems = Get-WmiObject Win32_ComputerSystem -Namespace “root\CIMV2” -ComputerName $strComputer
foreach($objItem in $colItems) {
“—————————— Sys Info ———————”
“Computer Name: “+ $strComputer
“Computer Manufacturer: ” + $objItem.Manufacturer
“Computer Model: ” + $objItem.Model
“Total Memory: ” + $objItem.TotalPhysicalMemory + “bytes”
}
}

# Create a GUI Form
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = “Data Entry Form”
$objForm.Size = New-Object System.Drawing.Size(800,600)
$objForm.StartPosition = “CenterScreen”

$objForm.KeyPreview = $True
#$objForm.Add_KeyDown({if ($_.KeyCode -eq “Enter”)
# {$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq “Escape”)
{$objForm.Close()}})

# Add a drop-down Combo box
$objComboBox = New-Object System.Windows.Forms.Combobox
$objComboBox.Location = New-Object System.Drawing.Size(250,250)
$objComboBox.Size = New-Object System.Drawing.Size(280,20)
$objComboBox.Text = “Please select”

# Add items to Combo box
$commands = @(“SysInfo”,”BIOSInfo”,”OSInfo”,”CPUInfo”,”DiskInfo”,”NetworkInfo”)
ForEach ($command in $commands){
$objComboBox.items.add($command)
}

# Add combo box to Userform
$objForm.Controls.Add($objComboBox)

# Set to the first item
$objComboBox.SelectedIndex = 0;

# Set selection to ComboBox selected text.
$selection = $objComboBox.Text;
write-host $selection

# Add a text box to the Userform
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(250,200)
$objTextBox.Size = New-Object System.Drawing.Size(280,20)
$objForm.Controls.Add($objTextBox)

# Add an OK button and name it as “Submit”
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(250,400)
$OKButton.Size = New-Object System.Drawing.Size(75,25)
$OKButton.Text = “Submit”
$objForm.Controls.Add($OKButton)

# Add a Cancel button
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(350,400)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = “Cancel”
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

# Add an Exit button
$ExitButton = New-Object System.Windows.Forms.Button
$ExitButton.Location = New-Object System.Drawing.Size(450,400)
$ExitButton.Size = New-Object System.Drawing.Size(75,23)
$ExitButton.Text = “Exit”
$ExitButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($ExitButton)

# Add a Text label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(250,180)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = “Please enter a comma separated list of servers:”
$objForm.Controls.Add($objLabel)

# Add a Text label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(260,100)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = “Windows Resource Management Tool”
$objForm.Controls.Add($objLabel)

# Set form on top
$objForm.Topmost = $True

# Show fim
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$x = $objTextbox.text
$vals = $x.split(“,”)
foreach ($strComputer in $vals){
write-host $strComputer
}

$OKButton.Add_Click({

switch ($objComboBox.SelectedItem)
{
“SysInfo” {SysInfo}
“BIOSInfo” {BiosInfo}
“OSInfo” {OSInfo}
“CPUInfo” {CPUInfo}
“DiskInfo” {DiskInfo}
“NetworkInfo” {NetworkInfo}

}
$objForm.Close()})

# Set selection to ComboBox selected text.
$selection = $objComboBox.Text;
write-host $selection
foreach ($strComputer in $vals){
switch($selection) {
“SysInfo” { SysInfo }
“BIOSInfo” {BiosInfo}
“OSInfo” {OSInfo}
“CPUInfo” {CPUInfo}
“DiskInfo” {DiskInfo}
“NetworkInfo” {NetworkInfo}
}
}

$x

Related posts
1. Stir fry a VBA application quickly
2.Building a respectable VBA with Excel application
3. Get your feet wet with Powershell GUI
4. Powershell GUI – Adding bells and whistles
5. Slicing and dicing with LogParser & VBA
6. Adventures in LogParser, HTA and charts.

Also see
Brewing a potion with Bluemix, PostgreSQL, Node.js in the cloud
A Bluemix recipe with MongoDB and Node.js A Cloud medley with IBM Bluemix, Cloudant DB and Node.js
– A crime map of India in R: Crimes against women
– What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress – Part 1
– Bend it like Bluemix, MongoDB with autoscaling – Part 1
– Analyzing cricket’s batting legends – Through the mirage with R
– Masters of spin: Unraveling the web with R

Find me on Google+