Tales from a weekend of PowerShell: Get-Needle -haystack ...

First to explain the title: Sooner or later I will stop banging on about hot-desking and the bedlam which is our office area - last week it did seem to plumb new depths with one team sitting round a speaker phone in the open plan office yelling into a conference call and another playing the flutes/recorders/penny whistles that they were giving away. Hot-desking only works if some people are deterred  from coming into the office, and with the summer holidays over and the house to myself again I can return to my pattern of coming into the office to meet people, and staying at home when I have work to do; and having at least one "car free day" per week.
Working at home, I find it quite hard to not have the laptop on my knee when there's something I'm only half interested in on the TV. And working to a deadline (like trying to get the PowerShell part of a book done in time for publication) if the laptop is there then work naturally takes over the time that you've got nothing better to do. Which is how most of my weekend ended up with PowerShell.

I've been doing a lot of work with WMI objects for this project - they have names like MSFT_SIPFederationExternalEdgeListeningAddressSetting or MSFT_SIPLocalNormalizationRuleData

To try to keep some consistency I typically have functions which go something like this

  • Get-OCSNormalizationRules - returns the all WMI objects for the class we're interested in.
  • List-OCSNormalizationRules - takes the result of the Get and formats it nicely
  • Export-OcsNormalizationRules - takes the result of Get and outputs selected fields to a CSV file
  • Choose-OCSNormalizationRules - takes the result of the Get makes a menu (and returns the Wmi Objects, so that all the properties are available)
  • New-OCSNormalizationRule - takes parameters needed to build a WMI object
  • Import-OcsNormalizationRules - takes a CSV file and for each entry invokes New
  • Update-OCSNormalizationRule - takes the same parameters as New, uses one to retrieve the WMI object, and the others to update fields in it
  • Delete-OCSNormalization rules - uses the same parameter as Update to retrieve the WMI object and deletes it

Obviously some functions don't make sense for some of the objects. Choose-OCS Users wouldn't have an impossible menu. New-OCS ServerPool is done by installing the server, and so on.

One thing that plagued Live Communications server 2005 was mis-configured certificates so we wanted to be able to show what was being use. But where to go to get this information ? - there are a hundred or so WMI classes beginning MSFT_SIP - different ones exist depending on the server role. I'd already got a list potentially interesting classes with

 get-wmiobject -list | where-object {$_.__class -like "msft_SIP*"}

So. I thought, why not dump out all of the classes. It's a bit daft, but if I send it to a text file I can just search for CERT and I'll find it and here's the line it took. 

 get-wmiobject -list | where-object {$_.__class -like "msft_sip*"} | foreach-object {get-wmiobject -class $_.__class} > temp.txt 

And hey presto 10 seconds in notepad had the reference I was looking for. What I had to do when I got that certificate was a whole other story, which I'll tell you all about some other time.

Technorati tags: Powershell