Learning PowerShell – Homework Eleven Answers


PowerShell Homework Eleven Answers

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. Why is it important to give your CSV file good header names?

You want to give your CSV headers good names so that they are readable throughout your code. In addition you may not want to make them too long because you will have to type out those headers every time you reference them in your code.

2. Why does your CSV file need good header names in the first place?

CSV files will need the headers so that PowerShell can identify the data in the CSV file. Remember that PowerShell is an object oriented scripting language, and providing that header data allows PowerShell to tag the data in the file.

3. Why may you choose to put your script directory into a variable?

You will most likely want to include one script directory variable in your script so that you don’t have to continually type absolute paths in your script. This will make the maintenance of your script easier if you have many files that you’re reading and writing from, or if you decide to share your script with someone else.

4. Why can if else statements be written in more than one way?

If else statements in its simplest form are a Boolean operation: that is true or false. Because of this you can write the condition in any way you like. You just have to remember to put the proper response in the proper code block so that the action you are expecting takes place when it’s supposed to.

5. In plain English explain how we are filtering the Get-Services command to only the one we have defined in our CSV file.

In plain English (if possible) we are calling the Windows Get-Service commandlet and using via the pipe “|” we are using the WHERE clause to search through every service that is currently running by the name of the service. Where the name of the current Get-Service object matches one that we have specified in our file we send that service object back to our $SERVICES_TO_CHECK variable for use in the following lines of code.


Leave a reply

eighty one − seventy four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.