writing scripts in Windows PowerShell ISE?

I want to write a script in Windows PowerShell ISE that will ask the user for their name and also ask a question to the user with three options. it need to run on of the options and display the output.
vivien DAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
There you go:
write-host " here you`n`tCan put your question`n`t and options in this line"

$answer = read-host "what would be your selection, Options(A,B,C)? "

switch($answer){
    "A"{
        #logic for Option A and takes "A or a" => (its not case sensitive)
        Write-Host "Option A Selected" -ForegroundColor Yellow
    }
    "B"{
        #logic for Option B
        Write-Host "Option B Selected" -ForegroundColor Green
    }
    "C"{
        #logic for Option C
        Write-Host "Option C Selected" -ForegroundColor Cyan
    }
    default{
        #logic for whatever option different than A B C
        Write-Host "No option selected" -ForegroundColor Black -BackgroundColor Yellow
    }
}

Open in new window

`n => go to the next line
`t  => print a tab.
4
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
This is Jose's original item with some edits to make the text stand out more and show you a little more of what can be done.

  For your purposes, you can just put the entire question into the pop-up box, and simply nest that inside your switch statement.

  Notice how you can get the text to display in the pop-up box based on how you space it in the read-host statement. :)

2017-11-20-03_16_24-Administrator_-W.png2017-11-20-03_24_04-Administrator_-W.png
Modified Code:

cls
switch(
read-host (
"Please Answer this Question:

  What Color would you Like to see as a result?
  
    A) Yellow Font, with a Black background
    B) Green Font, with a Black background
    C) Cyan Font, with a Black background
    
Please Enter your option (A,B,C) in the text box below:")){
    "A"{
        #logic for Option A and takes "A or a" => (its not case sensitive)
        Write-Host "Option A Selected" -ForegroundColor Yellow  -BackgroundColor black
    }
    "B"{
        #logic for Option B
        Write-Host "Option B Selected" -ForegroundColor Green  -BackgroundColor black
    }
    "C"{
        #logic for Option C
        Write-Host "Option C Selected" -ForegroundColor Cyan  -BackgroundColor black
    }
    default{
        #logic for whatever option different than A B C
        Write-Host "Entered Somethgin other than A, B , or C" -ForegroundColor Black -BackgroundColor Yellow
    }
}

Open in new window

1
oBdACommented:
An easy option to let a user pick one entry from a selection is Out-Gridview (requires PS 3.0 or later):
## The first line in the following Here-String is the csv header line; change as required. Columns can be added, too.
$Menu = @'
	"Option",			"Description"
	"Make coffee",		"You can always add milk."
	"Eat cake",			"Almond and chocolate available."
	"Knock knock",		"Who's there?"
'@ | ConvertFrom-Csv

Write-Host 'Waiting for you to select an option in the GUI popup ...' -ForegroundColor Yellow
$UserSelection = $Menu | Out-Gridview -Title 'Please select one option and click OK.' -OutputMode Single
If (-not $UserSelection) {
	Write-Warning "Canceled by user!"
	Exit
}
Write-Host "You selected '$($UserSelection.Option)' ($($UserSelection.Description))" -ForegroundColor White
Switch ($UserSelection.Option) {
	'Make coffee' {
		Write-Host "Brewing coffee ..." -ForegroundColor Green
	}
	'Eat cake' {
		Write-Host "Eating cake ..." -ForegroundColor Green
	}
	'Knock knock' {
		Write-Host "You're joking, right?" -ForegroundColor Green
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- oBdA (https:#a42375458)
-- Ben Personick (Previously QCubed) (https:#a42374869)
-- Jose [MCSE] Ortega C (https:#a42374710)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.