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?
 
oBdAConnect With a Mentor Commented:
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
 
Jose Gabriel Ortega CConnect With a Mentor CEO J0rt3g4 Consulting ServicesCommented:
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)Connect With a Mentor 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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.