James O'Neill's blog

Windows Platform, Virtualization and PowerShell with a little Photography for good measure.

Powershell and Paradigms of VB

Powershell and Paradigms of VB

  • Comments 3
  • Likes

Since I was talking about experiences from long ago in my previous post, here's another. When I was at University one of my tutors, Dr Brian Lings, used the word "Paradigm" in a lecture. And we all went "WHAT !", and went running to dictionaries to find out what he meant. He actually used in the context of looking at something written in one language but actually having the way-of-doing-things that you'd see in another.

I was reminded of this when I was asked to help with some powershell scripts for the OCS resource kit. I was sent a script which looked like this.

# Get all SIP domains 

$SIPDomains = Get-WmiObject -class MSFT_SIPDomainData

# For every SIP domain in environment write SIP domain info to standard output

foreach ($SIPDomain in $SIPDomains) {

write-host  "*******************************"

write-host  SIP domain: $SIPDomain.Address

write-host "*******************************"

write-host  `t Default Domain : $SIPDomain.DefaultDomain

write-host  `t Authoritative : $SIPDomain.Authoritative


Getting the WMI Object class MSFT_SIPDOMAINdata, gives a collection of Objects: one per domain. So we store that collection in a variable and use a for loop to go through each object and write its properties to to the screen. Simple

Well except for that fact that write-host can't be redirected to a file. We can't use Get-SIPDomains > domains.txt.

But even fixing that this isn't  powershell "style" - though I'm still learning what that is, exactly. It's written like we'd write VB.

Using LISP at university meant that grew to I like one function to feed into the next, so piping functions into each other seems natural and powershell gives me cmdlets like format-table to take the results of Get-WMIobject and reduce the For loop to one line.

Get-WmiObject -class MSFT_SIPDomainData | Format-Table Address, Authoritative, DefaultDomain.

 I'm beginning to see why they named it POWER shell; one of the other scripts I need to write for the OCS resource kit needs to get information from the event log.  I was presently surprised to find PowerShell has a Get-EventLog cmdlet. With Where-Object to filter the events I can do this in one line.


Technorati tags: ,
  • My experiences with PowerShell continue and every so often realize that I never really understood something

  • Day Three of Devin's notes from the UC Voice Ignite event in Sydney, Australia.

  • Day 3 ...

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment