I've been continuing to work on our development environment and staging servers looking at ways to automate things and Powershell seems to be the way to go. I found a great collection of functions ready to use that James O Neill has posted to codeplex, but last week I ran into some problems with them. Using the Get-VM function gave me no output as did a number of other get- functions.
It took a while as i gradually worked through the code trying to see where it was going wrong - debugging a new language is always a liitle bit challenging as you learn what the different syntax and constructions do, but very beneficial in terms of learning how it works. Anyhow eventually i got to the point where i could get the WMI objects to return only the host machine and none of the virtual machines. At this point something clicked, I can't remember what it was now, but I realised that I was running powershell under the administrator account but without elevated privileges. I ran a new instance of powershell "as administrator" and pulled in the hyperV.ps1 file. Typed Get-vm and hey presto the list appeared of all my VMs.
Whilst I appreciate what Microsoft is trying to do with UAC, I am beginning to wonder how many more times i am going to get caught out by it and whether we will all just end up turning it off!