Change Virtual Machine Owner in System Center Virtual Machine Manager

If you are using clouds in your Virtual Machine Manager installation with users creating their own virtual machines

John Savill

January 17, 2013

1 Min Read
Change Virtual Machine Owner in System Center Virtual Machine Manager

Q: How can I easily change the owner of a number of virtual machines in my System Center Virtual Machine Manager environment?

A: If you are using clouds in your Virtual Machine Manager installation with users creating their own virtual machines (VMs), you might need to change the ownership of VMs if a user leaves the company, for example. I created the following Windows PowerShell script that will replace all VMs owned by the first user with the second user specified.

$newOwnerVMs="savilltechcortana"$oldOwnerVMs="savilltechjohn117"Import-Module virtualmachinemanagerget-vmmserver savdalvmm12.savilltech.netget-scvirtualmachine | where {$_.Owner -eq $oldOwnerVMs} | Set-SCVirtualMachine -Owner $newOwnerVMs

In my environment, I then created a simple Orchestrator runbook that has an Initialize Data step that allows the old and new user to be passed, which is then used in the PowerShell. Then it's published in Service Manager, making it easily available.

Below is the runbook Initialize Data activity I use and the PowerShell in the Change Owner .NET activity. Note I'm running the PowerShell remotely on the System Center Virtual Machine Manager server, so I pass a VMM administrator credential.

$Username = "savilltechVMMAdmin"$Password = "Pa55word"$ServerName = "savdalvmm12"try{    $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force    $credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username,$securePassword    Invoke-Command -ComputerName $ServerName -credential $credential -ScriptBlock {    $oldOwnerVMs="{OldVMOwner from "Initialize Data"}"    $newOwnerVMs="{NewVMOwner from "Initialize Data"}"    Import-Module virtualmachinemanager    get-vmmserver savdalvmm12.savilltech.net    get-scvirtualmachine | where {$_.Owner -eq $oldOwnerVMs} | Set-SCVirtualMachine -Owner $newOwnerVMs    }}catch{Throw $_.Exception}

 

I then offer this through Service Manager.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like