Trying to make gui for input

I am trying o make this command in to a GUI.

<p class="x_MsoNormal">Get-WmiObject -Class win32_computersystem -ComputerName 10.XXX.XX.XX | select username</p> My desired result is to type the IP in the GUI and the out put would be the username who is logged in.

I have my GUI set up but I am not sure how to put in the command. I am bew to powershell so forgive me for ignornace.

# Load the Winforms assembly
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")

Create the form

$form = New-Object Windows.Forms.Form

#Set the dialog title
$form.text = “Find User”

Create the label control and set text, size and location

$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point 50,30
$label.Size = New-Object Drawing.Point 200,15
$label.text = “Enter IP Address”

Create TextBox and set text, size and location

$textfield = New-Object Windows.Forms.TextBox
$textfield.Location = New-Object Drawing.Point 50,60
$textfield.Size = New-Object Drawing.Point 200,30

Create Button and set text and location

$button = New-Object Windows.Forms.Button
$button.text = “Find User”
$button.Location = New-Object Drawing.Point 100,90

{Get-WmiObject -Class win32_computersystem -ComputerName 10.XXX.XX.XX | select username


You are almost there (untested):

$button.Add_Click({$textfield.Text = Get-WmiObject -Class win32_computersystem -ComputerName 10.XXX.XX.XX | select username})

There is missing