Freigeben über


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

Comments

  • Anonymous
    June 06, 2012
    Andrew, James O’Neill (@jamesone) should be @jamesoneill PowerShell 3 in Windows Server 2012  is definately the way forward. Regards Alan

  • Anonymous
    June 06, 2012
    Yes, I do like where V3 is going. I don't think I'm giving any secrets away when I say for the previous releases of Hyper-V the product team had to get the product out and didn't have time to do PowerShell first. They talked to me before I left to make sure that they weren't going to fall into any licence / intellectual property traps with the work I had done and what they were planning. I'm flattered that people say they "stole" my ideas, but the work always belonged to Microsoft, and what they took was taken with my blessing.

  • Anonymous
    June 25, 2012
    Interesting !!! Nice article.