Change Virtual Machine Owner in System Center Virtual Machine Manager

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="savilltech\cortana"
$oldOwnerVMs="savilltech\john117"
Import-Module virtualmachinemanager
get-vmmserver savdalvmm12.savilltech.net
get-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 = "savilltech\VMMAdmin"
$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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish