2017-05-08 59 views
2

我想創建一個功能的GUI從SCCM中刪除UUID。Powershell System.Windows.Forms.TextBox

我無法將寫入我的文本框中的值添加到打開的確認窗口中,當我單擊「刪除」時。

值顯示但「System.Windows.Forms.TextBox,文本:ANDWHATWASWRITTEN」

如何提取只寫在文本框的話?

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

您希望TextBox對象的Text屬性,而不是對象本身

"Are you sure you want to delete the the computer with this UUID: $($UUID.Text)" 
+0

曾爲利卡一個魅力!謝謝! –

相關問題