«

»

Apr
27

Change Owner of all your VM’s in SCVMM using PowerShell

I had to re-install my Systems Centre Virtual Machine Manager the other day due to a hardware failure on the blade, it wasn’t too bad as it was only managing 8 VM’s one of which I Was planning on moving my SCVMM onto a VM that was on the cluster, this just prompted me to do it sooner, rather than later!

I installed SCVMM 2008 R2 on this server and then connected to my HyperV Cluster, all ok, except one thing; all my VM’s had “Unknown” listed as their owner not “Domain\akemp” which they were before.

As I said there are only 8 VM’s so not a huge hardship to change manually, but if you had say 80 servers in the list then you would be there all day, and night probably.

So I thought there must be a PowerShell script to change this from “unknown” to me… there is.

Its a very simple command:

Get-VM -VMMServer “scvmmserver” | where {$_.Owner -eq “Unknown”} | Set-VM -Owner “domain\akemp”

All you need to do to run this script for you is replace “scvmmserver” with your servername, “Uknown” with the current owner and “domain\akemp” with the new owner you want to assign the ownership to

**Please note that you need to leave the quotation marks round the servername, current owner and new owner**

So I opened up notepad, created the command and saved as rename-owner.ps1 and then ran it…

…Did it work… No!

I got the following error:

image

To run any of the Virtual Machine Manager cmdlets you need to have the SCVMM admin console installed (which I do)

after doing a bit more digging there is a PowerShell tool in the Microsoft Systems Center –> Virtual Machine Manager menu Called PowerShell – Virtual Machine Manager.

I ran that and then pasted my command into there and it worked.

it took all of about 2 minutes to make the ownership of my VM’s to me from Unknown

Or if you want to run the script without pasting in the command to PowerShell add:

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

at the top of the script first, that should then run

Or run that from PowerShell ISE

Am picking up more about PowerShell today than I thought Smile

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>