Friday, May 17, 2013

What I Learned at the Scripting Games - Part 2

Script for event 3 has been a hit (so far)! It’s crowd score is tracking above 4 stars for now. That's a big improvement from last week!

This was the problem 

The positive reception seems to be mainly linked to the time spent making the output look pretty with some CSS. Setting the formatting so the script is super easy to read doesn't hurt either.

Script is here as an image because when you include HTML tags the blogger platform gets all huffy.

Someone pointed out that it could be more efficient. I’m doing;
Get-WmiObject win32_logicaldisk -computername $server | Where-Object {$_.DriveType -eq 3} |

Where it could be;
Get-WmiObject win32_logicaldisk -computername $server –filter=”Drivetype=3” |

Mine executes two commands (get-wmiobject and where-object) when the same result could be achieved with one. If this script was running over tens of thousands of hosts it might make a difference. Plus it’s neater with one command.

So lessons learned this week;
  • Make sure you are being as efficient as possible even if your script is only going to be run on one host today... That will almost certainly not be the case tomorrow
  • Spending a bit of effort making the output "pretty" is worth the effort
  • Spending time to make your script readable will help others comprehend what you are doing. It'll also help future you figure out what you were thinking
  • There may still a place for oddball humor in comments! 

No comments:

Post a Comment