Summary: The Scripting Wife offers her suggestions for Beginner Event 2 in the 2012 PowerShell Scripting Games.
Hi everyone. Sorry I did not get to blog earlier today. I have been really tied up with Beginner Event 3, and I wanted to get it submitted to PoshCode before I wrote my posting for today. Oh well. What can I say about Beginner Event 2? Here are the essential points, as I determined them:
1. Well first of all, I know I need to be able to get information about services. Use the Get-Command cmdlet if you are not sure what cmdlet to use to get information about services.
2, Now, the key thing about this event is that you need to find basically two things. First, you need to find all running services. Next, you need to find services that you can stop. To find out what property, you need to use the Get-Member cmdlet. So what you need to do is take the cmdlet you found by using Get-Command and pipe it to Get-Member. When you do that, look at the output for something that looks like it would tell you if you can stop a service.
3. The command should be able to run against a remote computer. So this means use the ComputerName parameter of the cmdlet. If you do use ComputerName, make sure you put some default in there. You can use LocalHost or $env:computername. I actually like using $env:computername (tab expansion actually works for this) because it returns the actual computer name, not like LocalHost does. Ed wrote a really cool blog for last years Scripting Games that I read when I was getting ready this year. It talks about handling the default condition, and if you read it and follow it, it should save you 1 point.
You know, this is about it. The rest of the stuff is saying don’t get too carried away. My entry was a single line command. I even used some aliases in it.
I hope this helps you with Beginner Event 2. Remember, you have until April 10, at 12:01 AM Redmond time (-8 GMT) to upload your script to PoshCode. I hope you get five stars on your script! Good luck to you.