0

I am working on creating a GUI based app with PowerShell. I am struggling with getting the text entered by the user in the textbox to be assigned to a variable.

I want the user to enter the server name in the textbox and use that text on button click for processing the rest.

Suppose $Textbox is the textbox while $Server is the server.

enter image description here

5
  • 2
    You would do well to read How to Ask as your question is missing some of the basics.. specifically any code (as minimal reproducible example) Commented Mar 23, 2018 at 14:58
  • My bad, missed the screenshot. @JamesC. Commented Mar 23, 2018 at 15:01
  • 1
    Screenshot of the form window itself is fine, but please don't post screenshots of code - post the actual code (maybe revisit the "Minimal, Complete, and Verifiable example" page linked by @JamesC.) Commented Mar 23, 2018 at 15:06
  • You probably want to research events. Keeping in mind you are now using .NET libraries within your powershell.... msdn.microsoft.com/en-us/library/… Commented Mar 23, 2018 at 15:17
  • Please do NOT post screenshots of code. Commented Mar 23, 2018 at 16:38

1 Answer 1

1

From the picture of what you posted... here is how you would handle the button click and passing the content of the textbox to the server function

function Server-Task {
    Param(
        [string]$textboxStuff
    )
    # ... Do Stuff ....
}

$Submit.Add_Click({Server-Task $Textbox.Text})

You could also just store the $Textbox.Text to a variable

Sign up to request clarification or add additional context in comments.

6 Comments

Was able to use $Textbox.text and assigned it to th variable I wanted. $Server = $Textbox.Text write-host $Server
Yes I used the $Textbox.text into a variable and then worked with the variable for my result-set.
@RamakantDadhichi Glad you were able to get it working. Did you get the button click working?
Yes,the app is working fine now. Will add more features soon.
@RamakantDadhichi Please remember to mark the answer so that others with similar questions know this worked
|

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.