2

I am trying to create a GUI for a funktion to remove UUID from SCCM.

I am having trouble to put the value written in my textbox to the confirmation window opened when i click "Delete".

The value is displayed but with "System.Windows.Forms.TextBox, Text: ANDWHATWASWRITTEN"

How to extract only the words written in the textfield?

enter image description here

Function Delete()
{  
Write-Host "Your choice is $Result"

Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::YesNoCancel
$MessageIcon = [System.Windows.MessageBoxImage]::Error
$MessageBody = "Are you sure you want to delete the the computer with this UUID: $($UUID.Text)"
$MessageTitle = "Confirm Deletion"
$Result = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)

Write-Host "Your choice is $Result"
}
Function Abort()
{
$DeleteUUIDfromSCCM.Close()
}

Function Generate-Form {

Add-Type -AssemblyName System.Windows.Forms    
Add-Type -AssemblyName System.Drawing

# Build Form
$DeleteUUIDfromSCCM = New-Object System.Windows.Forms.Form
$DeleteUUIDfromSCCM.Text = "Delete UUID from SCCM"
$DeleteUUIDfromSCCM.Width = 362
$DeleteUUIDfromSCCM.Height = 179
$DeleteUUIDfromSCCM.StartPosition = "CenterScreen"
$DeleteUUIDfromSCCM.Topmost = $True

$ComputerUUID = New-Object system.windows.Forms.Label
$ComputerUUID.Text = "Enter Computer UUID"
$ComputerUUID.AutoSize = $true
$ComputerUUID.Width = 25
$ComputerUUID.Height = 10
$ComputerUUID.location = new-object system.drawing.point(100,12)
$ComputerUUID.Font = "Microsoft Sans Serif,10,style=Bold"
$DeleteUUIDfromSCCM.controls.Add($ComputerUUID)

$UUID = New-Object system.windows.Forms.TextBox
$UUID.Width = 202
$UUID.Height = 20
$UUID.location = new-object system.drawing.point(71,39)
$UUID.Font = "Microsoft Sans Serif,10"
$DeleteUUIDfromSCCM.controls.Add($UUID)

# Add Button
$Delete = New-Object System.Windows.Forms.Button
$Delete.Location = New-Object System.Drawing.Size(70,80)
$Delete.Size = New-Object System.Drawing.Size(100,23)
$Delete.Text = "Delete"

# Add Button
$Cancel = New-Object System.Windows.Forms.Button
$Cancel.Location = New-Object System.Drawing.Size(175,80)
$Cancel.Size = New-Object System.Drawing.Size(100,23)
$Cancel.Text = "Cancel"

$DeleteUUIDfromSCCM.Controls.Add($Delete)
$DeleteUUIDfromSCCM.Controls.Add($Cancel)

#Add Button event 
$Delete.Add_Click({Delete})
$Cancel.Add_Click({Abort})


#Show the Form 
$DeleteUUIDfromSCCM.ShowDialog()| Out-Null 

  } #End Function 

  #Call the Function 
  Generate-Form

1 Answer 1

1

You want the Text property of the TextBox object, not the object itself:

"Are you sure you want to delete the the computer with this UUID: $($UUID.Text)"
Sign up to request clarification or add additional context in comments.

1 Comment

Worked lika a charm! Thank´s!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.