Ich versuche, eine GUI für eine Funktion zu erstellen, um UUID von SCCM zu entfernen.Powershell System.Windows.Forms.TextBox
Ich habe Probleme, den Wert, der in meine Textbox geschrieben wurde, in das Bestätigungsfenster zu bringen, das geöffnet wird, wenn ich auf "Löschen" klicke.
Der Wert wird angezeigt, sondern mit „System.Windows.Forms.TextBox, Text: ANDWHATWASWRITTEN“
Wie nur die Wörter in das Textfeld geschrieben extrahieren?
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
Arbeitete Lika ein Charme! Vielen Dank! –