posted
13/08/09
Get MAC Address (The GUI version)
By Fredrik WallUpdated version with ping control and with Windows forms.
function Ping-Status { param ($mysrv) $pingstatus = Get-WmiObject -Query "SELECT StatusCode FROM win32_PingStatus WHERE ADDRESS = '$mysrv'" if ($pingstatus.StatusCode -eq 0) { $true } else { $false } } #Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0 # Generated On: 2009-08-13 08:41 # Generated By: Fredrik Wall ######################################################################## #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 $label2 = New-Object System.Windows.Forms.Label $label1 = New-Object System.Windows.Forms.Label $textBox1 = New-Object System.Windows.Forms.TextBox $richTextBox1 = New-Object System.Windows.Forms.RichTextBox $btnGet = New-Object System.Windows.Forms.Button $btnClear = New-Object System.Windows.Forms.Button $btnExit = New-Object System.Windows.Forms.Button $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $btnExit_OnClick= { #TODO: Place custom script here $form1.close() } $btnClear_OnClick= { #TODO: Place custom script here $textbox1.text = "" $richTextBox1.text = "" } $btnGet_OnClick= { #TODO: Place custom script here $richTextBox1.text = "" $strComputer = $textBox1.text if (Ping-Status $strComputer) { $colItems = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -computername $strComputer | Where{$_.IpEnabled -Match "True"} foreach ($objItem in $colItems) { $myDesc = $objItem.Description $myMACAddress = $objItem.MACaddress $richTextBox1.text += $myDesc + " " + $myMACAddress + "`n" } } else { $richTextBox1.text = "Computer did not respond!" } } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $form1.Text = 'Get MAC address' $form1.Name = 'form1' $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 481 $System_Drawing_Size.Height = 510 $form1.ClientSize = $System_Drawing_Size $label2.TabIndex = 6 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 14 $label2.Size = $System_Drawing_Size $label2.Text = 'Information:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 69 $label2.Location = $System_Drawing_Point $label2.DataBindings.DefaultDataSourceUpdateMode = 0 $label2.Name = 'label2' $form1.Controls.Add($label2) $label1.TabIndex = 5 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 14 $label1.Size = $System_Drawing_Size $label1.Text = 'Computer:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 18 $label1.Location = $System_Drawing_Point $label1.DataBindings.DefaultDataSourceUpdateMode = 0 $label1.Name = 'label1' $form1.Controls.Add($label1) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 149 $System_Drawing_Size.Height = 20 $textBox1.Size = $System_Drawing_Size $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $textBox1.Name = 'textBox1' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 35 $textBox1.Location = $System_Drawing_Point $textBox1.TabIndex = 4 $form1.Controls.Add($textBox1) $richTextBox1.Name = 'richTextBox1' $richTextBox1.Text = '' $richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 86 $richTextBox1.Location = $System_Drawing_Point $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 457 $System_Drawing_Size.Height = 369 $richTextBox1.Size = $System_Drawing_Size $richTextBox1.TabIndex = 3 $form1.Controls.Add($richTextBox1) $btnGet.TabIndex = 2 $btnGet.Name = 'btnGet' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnGet.Size = $System_Drawing_Size $btnGet.UseVisualStyleBackColor = $True $btnGet.Text = 'Get' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 232 $System_Drawing_Point.Y = 475 $btnGet.Location = $System_Drawing_Point $btnGet.DataBindings.DefaultDataSourceUpdateMode = 0 $btnGet.add_Click($btnGet_OnClick) $form1.Controls.Add($btnGet) $btnClear.TabIndex = 1 $btnClear.Name = 'btnClear' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnClear.Size = $System_Drawing_Size $btnClear.UseVisualStyleBackColor = $True $btnClear.Text = 'Clear' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 313 $System_Drawing_Point.Y = 475 $btnClear.Location = $System_Drawing_Point $btnClear.DataBindings.DefaultDataSourceUpdateMode = 0 $btnClear.add_Click($btnClear_OnClick) $form1.Controls.Add($btnClear) $btnExit.TabIndex = 0 $btnExit.Name = 'btnExit' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnExit.Size = $System_Drawing_Size $btnExit.UseVisualStyleBackColor = $True $btnExit.Text = 'Exit' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 394 $System_Drawing_Point.Y = 475 $btnExit.Location = $System_Drawing_Point $btnExit.DataBindings.DefaultDataSourceUpdateMode = 0 $btnExit.add_Click($btnExit_OnClick) $form1.Controls.Add($btnExit) $richTextBox1.text = "Get MAC Address by Fredrik Wall, fredrik[dot]wall[at]riverpoint[dot]se" #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:

Comments
RT @walle75 Get MAC Address (The GUI version) | Fredrik Wall http://bit.ly/ELtg