2012 Scripting Games Beginner Event 1: Use Windows PowerShell to Identify a Working Set of Processes

2012 Scripting Games Beginner Event 1: Use Windows PowerShell to Identify a Working Set of Processes

Rate This
  • Comments 37

 2012 Scripting Games badge

Summary: Beginner Event 1 of the 2012 Scripting Games uses Windows PowerShell to identify a working set of processes.

About this event

Division

Beginner

Date of Event

4/2/2012 12:01 AM

Due Date

4/9/2012 12:01 AM

Event scenario

You are the network administrator for a small, single-location company. Your desktops are all running Windows 7, and your servers are all running Windows Server 2008 R2. Your company has a single domain, and Windows PowerShell remoting is enabled on all computers—both servers and desktops. Your boss is concerned because a number of users have complained that their computers are slow. This is surprising and alarming because each user received a new desktop when they were migrated to Windows 7. To better get a handle on what is going on with the desktop computers, your boss has directed you to ascertain the top ten processes that are consuming memory resources on each computer.

You decide, after doing a bit of research, that the working set of each process would be the best property to track. You also decide to use Windows PowerShell to gather the information. An acceptable output is shown in the following image.

Image of command output

Design points

  • There is no need to write a script for this event.
  • The command you use should be CAPABLE of running remotely against other computers in the domain, but you are not required to have multiple computers available for this scenario.
  • Because this command can be a one-liner, aliases are acceptable in your submission.
  • Your command should return an object that could be piped to additional commands.
  • You should be able to write the results of your command to a file if required (but writing to a file is not a requirement for this scenario).

2012 Scripting Games links

2012 Scripting Games: All Links on One Page

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. Good luck as you compete in this year’s Scripting Games. We wish you well.

Ed Wilson, Microsoft Scripting Guy 

Leave a Comment
  • Please add 2 and 4 and type the answer here:
  • Post
  • @Killian that is in fact, one of my favorite things about the Scripting Games, is seeing other peoples solutions. You will have to wait one week before you will be able to see other peoples answers ... for event two, you only have a few more hours to wait. I wish you luck in the games!

  • I have to say that when all I hear lately is that aliases should be avoided for hand-over/readability reasons I am surprised that this has become an exam design point - especially in the beginners section. I guess you could argue this because it is supposed to be a throw away one-liner but I would argue that tab completion would be a better skill to promote.

  • @Ken Hamilton I said that aliases are acceptable, not aliases are mandatory :-) You are confusing two different things. This question is all about quickly performing an interactive task. The "Aliases are bad" debate is specifically about production scripts --- not even about quick scripts. Aliases are not bad, they are a great way to quickly come up with code, and to minimize typing. For example, ps is two key strokes. Get-p<tab> is six key strokes. As long as you know that ps is an alias for Get-Process it is much faster (three times) less typing.

  • Ed, I'm confused by the grading here.  I received 2.5 point for my solution, and the comments were as follows:

    "Decent solution. What I would suggest: this is one-liner so aliases are more than welcome. Also: would be great to see in the command/ comment/ description how do you plan to implement remote capability."

    That seems to imply I lost out on potential points because I did not use aliases, and because I didn't describe how to use it remotely.  Your design points did not say anything about that being required, only that the commands we use are capable of running remotely.

  • @Erunama Hmmmm ..... if you have 2.5 points, then it means that you have received at least two grades. One better, and one not as good from the judges. The judges all have their own ideas of what is a good script, and what is not. The rules say that aliases are acceptable, not that they are required. Often a judge will mention things (I know that I do) in the comment that is NOT directly related to the actual grade I give. I want to give hints that might make you a better scripter. For me, when I am grading, if the design says an alias is acceptable, that means you will NOT loose points for using them, but you do not gain points for using them either. I have added that very comment, that the command could be shorter by using aliases, but it did not affect my specific grade. The grading is this: the command should be capable of running remoting = 1 point. The command should return an object = 1 point. You should be able to write to a file = 1 point. The script should work and meet the requirement of the scenario = 2 points. So there are your five points. You lose a point or two points if you miss any one of these things. Keep in mind, the judges all have their own ideas, I have given them guidelines, but they are all free to express their own judgement.

  • @erunama @IamMred Regarding alias use: I'm really hoping the other judges don't penalize for NOT using an alias (unless, of course, the guidelines would specifically say "use aliases").

    I completely understand the concept behind it, but I just cannot make myself use them in something that will be available "in print" online for new Powershell users to read. When I'm sitting at my desk, running quick one-liners to gather info, or even in a small script that I reuse often, it's Alias Invaders!

    I'm fairly new to Powershell and I still read things online that raise an eyebrow. But in print, it still looks "neater" to have the cmdlet typed out.

    Just saying... :)

  • @DawnVillejoin no I am not penalizing for not using an alias. I completely understand your point, because most aliases do in fact make the code harder to read. Not all aliases, but certainly most of them. This is especially true for beginners.

  • Somehow, 2 entries have been submitted by me for this ( both scripts the same ), kindly ignore any 1 of them.

  • @Srikanth I flagged your second entry for Beginner Event1 as a duplicate. It's grading will not enter into your final score. It should also be deleted (hopefully, but Joel is really swamped right now).

  • I am curious why my Event 1 script got 3 stars due to not spelling out parameters while another script, which abbreviated considerably more gets 5 stars.

  • @Joshua Taylor - I am guessing because since you didnt use a ComptureName parameter, your script doesn't look capable of running remotely.

  • More of an observation than a question... After reviewing some of the event 1 entries, I've noticed that some have used "Get-Process | sort WS -Descending | Select -First 10"

    Detail Point: The command you use should be CAPABLE of running remotely against other computers in the domain, but you are not required to have multiple computers available for this scenario.

    Scenario comment:  "Your boss has directed you to ascertain the top ten processes that are consuming memory resources on EACH computer."

    When using "Get-Process" against multiple computers, ie, Get-Process -ComputerName comp1,comp2...., it returns the top ten processes collectively from the set of computers, not EACH computer, not meeting the event requirement.

    Also, since the scenario states that remoting has been enabled across the domain, why not make use of that?

    Invoke-Command -ComputerName comp1,comp2 { Get-Process | Sort WorkingSet -Descending | Select -First 10 }

    or for the ones who enjoy aliases in one-liners:

    icm -cn comp1,comp2 { ps | sort ws -des | select -f 10 }

    This command actually returns the TOP TEN processes from EACH computer; and as an added bonus, and for logging purposes, it also returns a PSComputerName property :)

    **Of course, this one-liner is an assumption of mine (and I didn't include the computername parameter in the actual command, just in the usage comments)... I scored 3.5 on event 1 and could be way off base!!

    I hope I don't come across as a "know it all" or something of the sort... farthest from the truth!  I really just enjoy learning about Powershell and what it can do AND have fun while learning!!  Who knew, huh?

    Anyway, I just wanted to make that comment :)

  • @Dawn Villejoin Get-Process is able to go against remote computers. It therefore meets the requirements. Is it the best solution in this scenario? Probably not, because Get-Process requires special ports to be opened in the Windows Firewall, and Windows PowerShell remoting WE KNOW is enabled, and therefore would work. I actually like the Invoke-Command answer ... and probably give you a 5 on your solution. The other advantage to Invoke-Command is that it allows you to submit alternate credentials, and Get-Process requires impersonation. In the scenario I wrote, I was not worried about consolidated, or separately grouped output.

  • @IamMred - just curious, i got this comment on my script:  don't have to use invoke-command as get-process has a -computername parameter

    Not sure if it meant I should or shouldn't not of used it, or if it was just informational and that I didnt have to.

  • @Craig Jahnke you don't have to use invoke command as Get-Process has a computername parameter. See my above comment. The comment, if from me, was merely informational ... I did not count off for using invoke-command.

Page 2 of 3 (37 items) 123