PowerShell for Windows Admins

April 10, 2012  12:56 PM

Using aliases and the myth of the one-liner

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The beginners section of the scripting games can be often answered with one pipeline of PowerShell.

Notice that I stated one pipeline not one line

Since the early days of PowerShell there has been an almost mystical reverence  paid to the concept of the “one-liner” ie boiling the PowerShell script down to a single line. That worked as a concept in PowerShell v1 where all we had was the console. When PowerShell v2 appeared with the ISEit was time to ditch the one line concept and switch our attention to what is important – using the PowerShell pipeline.

The pipeline symbol acts as a line continuation character so in ISE or any other PowerShell aware editor/environment you can split your pipeline over multiple lines of text BUT STILL HAVE A SINGLE PIPELINE.

Its more readable and easier to work with especially when debugging.

With PowerShell v3 and the changes to ISE it is finally time to kill the myth of the one liner and actually be honest about what we are trying to achieve – the one pipeline.

In a similar vein there is a lot of talk about how we should use aliases at the command prompt.


With tab completion it is almost as quick to use the full name for cmdlets and parameters especially if you have to look up the alias. If you like them fine but I prefer not to use them so that what ever I experiment with at the prompt can be copied straight into scripts.

April 9, 2012  2:44 AM

Scripting Games 2012 Comments: #2 Read the help file

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’m seeing a lot of scripts where code is used to perform an action that is available as a parameter on a cmdlet that is used earlier in the pipeline.


Read the help file for the cmdlets you are going to use to see how you can get PowerShell to do the work for you instead you having to create and test code

April 8, 2012  7:54 AM

Scripting Games 2012 Comments: #1 Line Continuation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

As with previous games I’ll publish a series of comments on the games. I won’t deal with any event specific issues until the games events are all closed but there are some things coming through that while not affecting any gradings don’t make the best use of PowerShell.

The first one that’s jumped out is line continuation.

I’ve seen a number of examples like the following two

get-service | `
sort status  -Descending


get-service  `
| sort status  -Descending

Both work but the line continuation character is unnecessary

All you need to do is

get-service |
sort status  -Descending

The pipeline symbol also works as a line continuation.

A minor point maybe but let PowerShell do the work for you

April 6, 2012  7:32 AM

2012 games–5 events published

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We’re just about at the halfway point with 5 events available – remember there is only a week to complete an event. Deadlines start on Monday.

The overall quality of submissions from what I’ve seen so far is up on last year which is an achievement. What is staggering is that we’ve already had as many entries as we had in total last year.

Its going to be a busy time for the judges Smile

April 2, 2012  12:39 PM

Scripting Games have started

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Jump over to http://blogs.technet.com/b/heyscriptingguy/

for event 1 in the beginners and advanced categories

April 2, 2012  12:33 PM

Finding the primary name of a DNS alias record

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A forum question asked how to find the primary name from an alias or CNAME record.

Get-WmiObject -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_CNAMEType `
-Filter "ContainerName = 'Manticore.org'" -ComputerName server02  |             
select @{N='Alias'; E={$_.Ownername}}, Primaryname            


use the MicrosoftDNS_CNAMEType class. Filter on the domain ie containername.  ComputerName holds the DNS server name.

Change OwnerName to Alias in a select calculated field

April 1, 2012  10:09 AM

MVP renewal 2012

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

My MVP award was renewed for another year today.

Thank you to Microsoft for bestowing the honour for the fifth year and thank you to all of the people who’ve helped me gain this award by posting questions, reading my blogs, listening to talks etc.

March 30, 2012  8:49 AM

PowerShell in Practice offer today only

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Manning have PowerShell in Practice on a half price offer today. Go to www.manning.com and use code dotd0330cc when ordering

March 29, 2012  2:57 PM

UK PowerShell Group March 2012 meeting recording

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


The recording, slides and demo script from the session on CIM cmdlets – Tuesday 27 March is available



March 26, 2012  11:38 AM

PowerShell Deep Dive 2012 Agenda

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The agenda for the PowerShell Deep Dive next month has just been published on the PowerShell team blog


If you are already booked to go – looking forward to meeting you.  If you’re thinking of going last years event was amazing. If you are interested in PowerShell it is the place to be

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: