What’s happening these days…

#powershell edit this page

It has been quiet around here for some time, so what have I been up to?

Well, on one side, I’m having fun at the Scripting Games (http://scriptinggames.org/) where I learn quite a bit (more from reviewing other entries, than from my own coding) and try to to improve my PowerShell skills. I’ll point out some of the things I’ve learned later on.

On the other side, I’ve decided to quit my job in the heart of the Italian Alps and accepted a role in Germany, in the nice city of Paderborn. So the last few weeks have been pretty busy for me, moving my stuff from northern Italy way up to northern (at least for me) Germany. Right now I am trying to get used to my new surroundings and I do learn something every day :)

So, what are my key takeaways from the Scripting Games so far?

  • Standard cmdlet parameter names: While I did know that there was a list of allowed Verbs (Get-Verb), I wasn’t aware that there was something similar for parameter names and types, too. Check out MSDN for more information.
  • Help and comments should be nested under the function, so if you are used to just press “Ctrl+J” to insert a new “empty” function and start from there, remember to move the help inside the function { } block.
  • ConvertTo-HTML has some really neat parameters like –Head, –PreContent and –PostContent so you can enhance and customize the HTML report generated by the cmdlet.
  • I started to use splatting to set parameter values and think this is really useful, basically you assign common values for parameters to a hash table and pass it to the cmdlet. I’ll post quick example later.
  • Filter, I tend to get every possible bit of information and then use Where-Object to select the few properties I really need, that’s not really efficient as most cmdlets provide a way to filter or just ask for the properties you need.

And here comes the example for splatting:

if ($Credential) {
    $wmiParam = @{'Credential'=$Credential; 'ErrorAction'="Stop"}
} else {
    $wmiParam = @{'ErrorAction'="Stop"}
Get-WmiObject @wmiParam –ComputerName “myComputer” –Class “Win32_Processor”

This passes a hash table (wmiParam) to the Get-WmiObject cmdlet, so I don’t have to set the ErrorAction every time and the Credential parameter is only used when a $Credential object exists.


Yeah, and that’s what’s new with me :)