Learning PowerShell – Homework Thirteen Answers
PowerShell Homework Thirteen
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 the $TIMER variable so important in our service monitoring script?
The timer variable is important because if we didn’t set it appropriately the sleep command wouldn’t function properly. This would mean that the loop we’re using in our PowerShell script would consume more resources than needed.
2. Why do we never enter a $RUN = “false” condition into the monitoring script?
We never set the $RUN condition to “false” because as long as the server is running we want to monitor our critical services.
3. Why is breaking longer lines in our scripts into smaller lines beneficial?
Breaking long lines into smaller ones simply makes the scripts easier to read. Look how easy it is to read the Send-MailMessage block because we’ve broken each of the options onto a separate line.
4. Explain in your own words how we are comparing the desired state of the service we are trying to monitor with the state of the service on the system?
This is an important part of the script to understand. We are reading in the service names in from our CSV file and then which each loop we are getting a list of all the services where the service name matches the current service from our CSV file we are looking for. We need to make sure that we are constantly getting status of the services we are looking each time the script loops through. If we didn’t keep refreshing this data the script wouldn’t be very useful. Once we have this information we can match it against the desired state in the CSV file.
5. What improvement do you think can be made to the monitoring script? For example what would happen if the SMTP server was not responding?
Ideally we should send out self a beacon home e-mail every hour, 30 minutes, 15 minutes, or however frequently the criticality of your services need. This would be a great extra step to build into the script on your own. If you know that your script should give you a status every hour even if thing is running that you know that your server and script is still alive and services are running.