Learning PowerShell – Homework Nine Answers
PowerShell Homework Nine
By: Steven Aiello
Answer the questions as best as possible in your own words. By answering the question in your own words you will learn more than simply repeating what you’ve heard. You are encouraged to visit the source links in the lessons to do more research on the subject.
Remember the point of the homework is not simply to finish, but to learn!
1. From your own thoughts and reasoning why is it good only to accept known good input from users and disregard all other input?
Since you can’t trust user input you should always only accept a certain range of known good values. All input should be tested before it’s processed.
2. What is the command that PowerShell uses to solicit user input?
3. Describe the difference in what is displayed if you use the above command from the PowerShell ISE or from the PowerShell command prompt.
If you use Read-Host in PowerShell ISE there will be a pop-up box. If you’re using Read-Host from PowerShell command line you will simply be presented with a command prompt.
4. In your own words why would you choose to use a switch statement over elseif statements.
An elseif block with many options can become a little complex. A switch block is a very clean way of testing for many conditions in a structured manor.
5. Write a PowerShell script that creates a menu of your choice, accepts the user input, and tells them what they selected. All other options entered in should produce an error.