Insufficient data from Andrew Fryer

The place where I page to when my brain is full up of stuff about the Microsoft platform

PowerShell convert

Back in the day I worked with this amazing guy James O’Neill (@jamesoneill)  who really got into PowerShell and had it doing all sorts of clever things like geo tagging his dive photos based on data form his watch and camera.  On the serious side he developed a PowerShell Configurator (which is still on Codeplex)with which you could manage a server core installation spin VM and change their properties.  Sadly James is no longer at Microsoft, but hopefully he likes where PowerShell 3 in Windows Server 2012 is going, indeed some of the commands bear a striking similarity to his configurator.

My point here is that in Windows Server 2012 PowerShell is now embedded even more deeply in the operating system,  so you can do far more, far more easily. My three simple examples are:

New simple commands:

Where James or you had to get deep into wmi calls to get stuff done with Hyper-V for example, there are now simple commands e.g.

get-vm

Which returns a list of virtual machines

Simple syntax

If you look at any serious Powershell 2 script you’ll see $_. cropping up somewhere. Essentially that is just a self reference to the object you are working on.  For example if I then pipe the output of get-vm into a query to find out which VMs are enabled for Replica in Windows Server 2012 I would type ..

get-vm | where {$_.ReplicationState –eq ‘disabled’}

However this can be simplified In Powershell 3 to

get-vm | where ReplicationState –eq ‘disabled’

Simple testing

I like the new –whatif switch as in

checkpoint-vm –name “DC01” –whatif

will tell me what the command will do.

Then there’s the new version scripting tool PowerShell ISE in Windows Server 2012

powershell

and as you can see it has :

  • Intellisense
  • cmdlet lookup (top right)
  • help on parameter completion which you can then copy onto the script window (bottom right).

So I am now officially a PowerShell convert, though it will be some time before I would claim I am an expert.

To try this stuff I used  Windows Server 2012 Release Candidate with the Hyper-V role enabled