$x = InputBox("Enter something >", "Title")
Is not the wat to do this, at least not completely.
There are a plethora of ways to do this. It’s just a matter of what you feel works for you.
What you are showing will throw errors, because it is not a PS cmdlet. It is some custom function someone wrote that is being called.
Yo can even use the PS help system to create input boxes like the below
$FirstName, $LastName, $Password
Show-Command -Name New-InputBox
To get a GUI input box, it really depends on what you are asking of the user. Meaning, passwords, computer name, username, etc.
To get a user password via a GUI, that is what
… is for, but there are other ways.
If you want a user name, computer name etc… Just use .Net direclty.
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "Lastname")
"Your name is $name"
Again, there are lots of samples of this PS GUI sort of thing all over the web, on youtube, ms virtual academy, ms channel 9, ms powershellgallery.com and forums like this. Just use your search engine to find them.
That OK/Cancel stuff is from the .Net approach, like this. Well, this is just a msgbox, without the input part.
Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::YesNoCancel
$MessageIcon = [System.Windows.MessageBoxImage]::Error
$MessageBody = "Are you sure you want to delete the log file?"
$MessageTitle = "Confirm Deletion"
$Result = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
'Your choice is $Result'
Or even this…
$d = [Windows.Forms.MessageBox]::show("PowerShell Rocks", "PowerShell Rocks",
If ($d -eq [Windows.Forms.DialogResult]::Yes)
'Yes, PowerShell Rocks'
"On no, you don't like me"
If you want to do your own forms, and don’t have the $$$ to pay for a designer tool, Sapien’s PowerShell Studio - https://www.sapien.com/software/powershell_studio, there are free resources to do this, like https://poshgui.com or you can hard code it in for free in PowerShell_ISE (already on your computer by default, well, Windows) or Visual Studio Code (you have to download). Learning and using WPF (Windows Presentation foundation) for PS GUI development is not that hard and with the GUI drag and drop editors, those write the form code for you, but you still have to manually add the other code to make it do anything other than just display on your screen
So, again, lot’s of ways to do this.
Just search for ‘PowerShell GUI development’, or ‘writing PowerShell GUI’ in you search engine of choice or on YouTube and you’ll find a lot.