Showing posts with label Scripting Games. Show all posts
Showing posts with label Scripting Games. Show all posts

Monday, April 9, 2012

2012 Scripting Games Beginner Event 1

Being my first year entering the games, I am by no means an expert! I just want to express my view on each event of the Scripting Games. Here's my take on #2012SG Beginner Event 1... This is solely my opinion!  Also, this event has now been closed, so I'm not giving away any answers.
I've since gained a better understanding of reading the design points and sort of knowing what to expect (at least I hope so for my sake).  You may interpret things much more differently than I have.
Here are my "interpretations/comments" on the design points of the event.

Full details of the event: Scripting Games Beginner Event 1

Use Windows PowerShell to Identify a Working Set of Processes

 

There is no need to write a script for this event.

Great! This tells me that maybe it can be done with a one-liner!

 

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.

CAPABLE tells me that I need to use a command that can access a remote computer. So my first thought is Get-Process. That cmdlet has a -ComputerName parameter. As I did a bit of testing, with one computer (then with multiple), I began to notice something. When running the Get-Process cmdlet against multiple computers, the result is a collection of processes from ALL computers. So when I sort by WorkingSet, it may list a few from COMP1 and then a few from COMP2, etc.

Now according to the scenario, "your boss has directed you to ascertain the TOP TEN processes that are consuming memory resources on EACH computer." The scenario also states, "Your company has a single domain, and Windows PowerShell remoting is enabled on all computers," so I decided to use Invoke-Command instead of Get-Process alone. This seemed to work better since it would select the TOP TEN processes from EACH computer.

Now, even though Invoke-Command DOES work on remote computers, what I should have done was actually typed the -ComputerName parameter and used either localhost or $env:COMPUTERNAME (using this also allows for logging if needed) as the value (I think that cost me a point -- one judge scored it as a 4).

 

Because this command can be a one-liner, aliases are acceptable in your submission.


After viewing some of the other Event 1 scripts submitted, participants comments on the Hey Scripting Guy! Blog posts, and also taking note of what some of the judges have commented, here is where I find some inconsistency in judging.  The design point says aliases are ACCEPTABLE... not REQUIRED!  As I've commented before on one of the Hey Scripting Guys! Event posts:
I completely understand the use of aliases.  I use them myself when sitting at my desk and want to quickly gather information or run a command.  They are wonderful!! But I can't make myself use them in something that will be in "print" for others to see, for other beginners to decipher.  The beauty of Windows Powershell is the fact that it is so easily read and understood as is.

When I type out:
Get-Process | sort -Property WS -Descending | select -First 10
It seems much neater and much more readable than:
gps| sort ws -des | select -f 10

If someone wants to use aliases, then that's definitely their choice.  To each their own!  And hey, guess what?! The two above scripts do EXACTLY the same thing! Points should NOT be taken away when the design point specifically said aliases are acceptable! To me, the point was accomplishing the task at hand.

Is this why one judge scored it as a 3? I wish I knew -- that judge did not leave a comment.

 

Your command should return an object that could be piped to additional commands.


This tells me that I want to keep the integrity of the objects that I am working with.  I didn't want to kill any puppies ;)
When all was 'said and done' so to speak, and piped to Get-Member (actually, on my end, I do use gm as an alias), this tells me that the object type is Selected.System.Diagnostics.Process.  Normally, the Get-Process command (which I used within the script block of Invoke-Command) will return the type System.Diagnostics.Process.  I also tested this by piping my command to the Out-File cmdlet with success.

 

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).


I did some testing with the command I had done.  It can be exported to a CSV file and also output to a text file.  I included an example of how this is done in a usage comment. It wasn't a requirement, but it should be able to be done.

So there's my view on Event 1.  And I have to say that I have never used Get-Help, read the about_ files, or learned so much in a week.... while having fun!!!!  I am really enjoying this!  I thank everyone involved in making the Scripting Games happen and pray that it is around next year, so that maybe I can try my hand at the Advanced category!!

My score for event 1 as of this blog post: 3.5 stars

Happy Scripting!
Dawn Villejoin
@aspiringtech