question

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 asked PowerShelly-7438 commented

message box show more info than expected from the input

 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
    
 $objForm = New-Object System.Windows.Forms.Form 
 $objForm.Text = "Testing"
 $objForm.Size = New-Object System.Drawing.Size(400,500) 
 $objForm.StartPosition = "CenterScreen"
    
 $objForm.KeyPreview = $True
 $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 
     {$x=$objTextBox.Text;$objForm.Close()}})
 $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 
     {$objForm.Close()}})
    
 $OKButton = New-Object System.Windows.Forms.Button
 $OKButton.Location = New-Object System.Drawing.Size(20,400)
 $OKButton.Size = New-Object System.Drawing.Size(75,23)
 $OKButton.Text = "OK"
 $OKButton.Add_Click({$x=$objTextBox.Text;$u = $objTextBox2.Text; $objForm.Close()})
 $objForm.Controls.Add($OKButton)
    
 #name
 $objLabel = New-Object System.Windows.Forms.Label
 $objLabel.Location = New-Object System.Drawing.Size(10,80) 
 $objLabel.Size = New-Object System.Drawing.Size(280,20) 
 $objLabel.Text = "Please enter your ID:"
 $objForm.Controls.Add($objLabel) 
    
 $objTextBox = New-Object System.Windows.Forms.TextBox 
 $objTextBox.Location = New-Object System.Drawing.Size(10,100) 
 $objTextBox.Size = New-Object System.Drawing.Size(280,20) 
 $objForm.Controls.Add($objTextBox) 
    
 $objForm.Topmost = $True
    
 $objForm.Add_Shown({$objForm.Activate()})
 [void] $objForm.ShowDialog()
    
 #[System.Windows.Forms.MessageBox]::Show("$objLabel","TestMSG","OkCancel")
 [System.Windows.Forms.MessageBox]::Show("$objLabel.Text","TestMSG","OkCancel")

With $objlabel.text i got this message:
System.Windows.Forms.Label, Text: Please enger your ID:. Text


with only $objlabel, I got this message:
System.Windows.Forms.Label, Text: Please enger your ID:.

All i want is to show/display user's input not the whole line after =


windows-server-powershell
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Why are you using a "Label" control??? All that contains is the text of the label that appears on the form (probably right next to the TextBox into which you enter data). Try using the $objTextBox instead.

0 Votes 0 ·

because i was searching google and found this example that can have multiple questions and input in one popup. where if i use inputbox, it is one popup per question.

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered PowerShelly-7438 commented

Remove the quotes.

 [System.Windows.Forms.MessageBox]::Show($objTextBox.Text,"TestMSG","OkCancel")

Or code it like this to add more text.

 [System.Windows.Forms.MessageBox]::Show("Thanks $($objTextBox.Text)","TestMSG","OkCancel")

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

so this works if i have only one.

Once i have several $objTextBox1.text $objTextBox2.text $objTextBox3.text
i need a " "
and when i do, the issue arise.

I'm using Show just to test. once it works i will use invoke to run ps1 file on remote with parameter provided from $objTextBox**

example:
Invoke-Command -ComputerName www.shelly.com -filepath \\shelly\d$\temp\adduser.ps1 –siteName $objTextBox1.text -certType $objTextBox2.text type $objTextBox3.text –email $objTextBox4.text –dept $objTextBox5.text
`




0 Votes 0 ·

Sorry, nevermind, the 2nd options works.

0 Votes 0 ·
PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 answered

Thanks Moto,
I thought i had tried $objTextbox and didn't work. I forgot to add the .text like i did with $objlabel.txt

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.