SCCM and Powershell

I am building a wake on lan tool for the help desk. The tools gets the info like MAC and IP from SCCM. The help desk will search using the user name or computer name. My problem is how to pass the value from a textbox to the sccm query.

This is a sccm query

Get-WmiObject -ComputerName $SiteServer -Credential $cred -Namespace  "Root\SMS\Site_$Sitecode"`
-Query "select SMS_R_System.Name, SMS_R_System.IPAddresses, SMS_R_System.MACAddresses from  SMS_R_System where SMS_R_System.LastLogonUserName = ##PRM:SMS_R_System.LastLogonUserName##

I want

Get-WmiObject -ComputerName $SiteServer -Credential $cred -Namespace  "Root\SMS\Site_$Sitecode"`
-Query "select SMS_R_System.Name, SMS_R_System.IPAddresses, SMS_R_System.MACAddresses from  SMS_R_System where SMS_R_System.LastLogonUserName = $textbox.text"

Here is the script

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

$SiteServer = 'HECFGMGR03.leggmason.com' 
$SiteCode = 'LEM' 
#get-Username from sccm
$computers = Get-WmiObject -ComputerName $SiteServer -Namespace  "Root\SMS\Site_$Sitecode"`
-Query "select SMS_R_System.Name, SMS_R_System.IPAddresses, SMS_R_System.MACAddresses from  SMS_R_System where SMS_R_System.LastLogonUserName = 'username'" | select Name, MACAddresses, IPAddresses  ##PRM:SMS_R_System.LastLogonUserName##

foreach($computer in $computers){
    $Macaddress = ($Computer.MACAddresses -replace ':', "")
    $IPAddress = $Computer.IPAddresses

   # & "C:\Scripts\PowerShell\wol\WolCmd.exe" $Macaddress $IPAddress 255.255.255.0 7 
   Write-Host "Checking $($computer.name) to see if it's awake"
    Write-Host $Macaddress, $IPAddress
}
$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Wake Up Computer"
$objForm.Size = New-Object System.Drawing.Size(400,300) 
$objForm.StartPosition = "CenterScreen"
$objForm.MaximizeBox = $false

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

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
    {$objForm.Close()}})


    # Create a group that will contain your radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = '40,20'
$MyGroupBox.size = '300,100'
$MyGroupBox.text = "Wake up computer by:"

$rbtncomputer = New-Object System.Windows.Forms.RadioButton
$rbtncomputer.Location = '150,30'
$rbtncomputer.size = '120,20'
$rbtncomputer.Checked = $true
$rbtncomputer.Text = "Computer Name"

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(50,220)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Wake Up"
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click({Getcomputer})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(270,220)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

#$objLabel = New-Object System.Windows.Forms.Label
#$objLabel.Location = New-Object System.Drawing.Size(10,50) 
#$objLabel.Size = New-Object System.Drawing.Size(280,20) 
#$objLabel.Text = "Wake up computer by:"
#$objForm.Controls.Add($objLabel) 

#Textbox Input
$objTextBox = New-Object System.Windows.Forms.TextBox 
$objTextBox.Location = New-Object System.Drawing.Size(60,90) 
$objTextBox.Size = New-Object System.Drawing.Size(260,20) 
$objForm.Controls.Add($objTextBox)

   # Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($rbtncomputer))
#$MyGroupBox.Controls.AddRange(@($rbtncomputer,$rbtnuser))
$objForm.Controls.Add($MyGroupBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
$objForm.AutoSize = $false
[void] $objForm.ShowDialog()

I am still working on it.

Why are you not loading the SCCM PowerShell module when running the script?