I need a script with a menu. The purpose with the menu is that, if i ex. press 1 it should run a command, in this case install a printer, but i cant quite find out where to start.
Im not that hardcore to powershell, but i have to learn somehow
I have googled that too but the problem is, how do i make a selection that runs a command when i press 1. ex. add-printer “and the command here” i hope this make sense
The easiest and most promissing way of asking questions about code is to share the code you have problems with.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Well i can try to show with a small script where you can select a color.
$red = New-Object System.Management.Automation.Host.ChoiceDescription '&Red', 'Favorite color: Red'
$blue = New-Object System.Management.Automation.Host.ChoiceDescription '&Blue', 'Favorite color: Blue'
$yellow = New-Object System.Management.Automation.Host.ChoiceDescription '&Yellow', 'Favorite color: Yellow'
$options = [System.Management.Automation.Host.ChoiceDescription[]]($red, $blue, $yellow)
$title = 'Favorite color'
$message = 'What is your favorite color?'
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
If the red color is ex. printer 1 then when you press red in the popup window, then it should run this command:
add-printer -connectionname "here is where the printer is located"
if i should make it so i can select the network printer and install it, from ex. a .txt file where the printer installation has the code to install or just select the printer from the list.
You should have read the rest of the blog post about how to build a PowerShell menu as well …
Getting the user input is just the first step. Now you have to evaluate it either with a simple if condition if it’s just a “yes” or “no” choice or with a switch statement if there are more options available.