Migrating VM Role from One Subscription to Another in Azure Pack


First I would like to note that the solution below is not official guide from Microsoft and you should use it at your own risk.’’

Note: The PowerShell commands provided may have different values than the once showed in the screenshots.

In the past I’ve show you a way to assign Tenant User role and Owner to a VM which basically covers the scenario of moving a VM created by VM template to a subscription in Windows Azure Pack.

In this post I will show you how to move VM role from one subscription to another. To do this let’s see what objects are created and how they relate in VMM when VM Role is created trough WAP:

Virtual Machine –> Computer Tier –> SCService –>CloudService.

As I’ve show you in the previous blog post each Virtual Machine instance has UserRole and Owner properties. We can use them to move VM to another user role (subscription in WAP) but if we do that with VM that is created from VM role we will receive message like this:

Set-SCVirtualMachine : Unable to perform the operation because the object cannot have a different owner than its parent (parent’s owner is ). (Error ID: 26706)

If you are familiar wit the architecture of VMM you will know that VMM works with objects and these objects can have other parent and child objects. As it is the case with VM Roles we have the following relationship:

Virtual Machine –> Computer Tier –> SCService –>CloudService.

So logically we should change first the User Role and the Owner of the parent object. Next inline is Computer Tier but that particular object does not have properties UserRole and Owner so we move to the next one. SCService has UserRole and Owner properties. By knowing the name of the VM or the ID you can easily find to which SCService that VM is related:

$VMobj = Get-SCVirtualMachine -Name VM01

$SCServiceID =$VMobj.ComputerTier.ServiceId

$SCServiceObj=get-scservice –ID $SCServiceID

Now that we have the SCService I would like to pick the User Roles that I will be using in a variables.

I would like to take the Administrator user role in a variable:

$AdminRole=Get-SCUserRole –Name “Administrator”

I would like also to take the User role which we will transfer the VM Role:

$DstTenantRole=Get-SCUserRole –Name “stas@outlook.com_aa764fbe-824d-4ad0-ab5b-a47b5954d4a2”

Next step is to first assign the SCService to the Administrator User role:

get-scservice -ID $SCServiceID | Set-scservice -UserRole $AdminRole –Owner “Dev\stanislav.zhelyazkov”

Note: When you execute the command above it will print out the properties of the changed SCService but in those you may not see the UserRole and the Owner changed. To see those changes open new PowerShell console and execute those commands again:

$VMobj = Get-SCVirtualMachine -Name VM01

$SCServiceID =$VMobj.ComputerTier.ServiceId

$SCServiceObj=get-scservice –ID $SCServiceID

get-scservice -ID $SCServiceID

In the newly opened console you should see those changes. I am not sure why this is happening I guess some caching.

clip_image002

It is pretty interesting that when you change the UserRole and the Owner of SCService you will see those properties changed for the VMs under it:

image

Now our VM that was previously assigned to Tenant User Role and another Owner is now assigned to Administrator User Role.

Let’s now switch from Administrator User role to our other Tenant User role.

get-scservice -ID $SCServiceID | Set-scservice -UserRole $DstTenantRole  –Owner “stas at outlook.com”

Note After executing this command you will need again to open new PowerShell console to see the changes:

clip_image002[8]

And of course UserRole and Owner properties are also changed for the VM/s under that SCService.

image

Changing these properties of SCService and VM will not show the VMs on the Azure Pack Tenant Portal for the User role we’ve assigned them above. The reason for this is Azure Pack has two ways to get VM information – one is trough VM role and the other is directly trough VM instance. If VM instance is not linked to VM role than that VM will be get trough User Role and Owner Properties of the VM but if that VM is linked to VM role than WAP will try to get the VM trough something CloudService. That CloudService is located in VMM again and it is basically the master object in our scenario. So in short we need to change UserRole and Owner properties of CloudService.

We can easily find all cloud services with the following command:

get-cloudservice –all

From the output we can easily find the specific cloud service that we want and assign it new UserRole and Owner:

Get-CloudService -id ba48e972-9269-4f94-af73-5be7ea78af17 | Set-CloudService -UserRole $DstTenantRole –Owner “stas at outlook.com”

Again to see the actual UserRole and Owner changed we need to open new PowerShell console and get the information from there:

Get-CloudService -id ba48e972-9269-4f94-af73-5be7ea78af17

clip_image002[10]

Note: When you assign new –Owner value make sure that the new value you assign is different than the current one. I’ve found out that if values are the same you may not be able to change UserRole.

When you do that last change you should be able to see the VM Role and its VM/s to the new subscription:

clip_image002[12]

clip_image002[14]

 

Note This scenario is only tested with SC 2012 R2 UR4. Do make sure you are using the latest UR when you are trying this solution.

 

There is another way to transfer VMs from VM Role from one subscription to another. You can delete the VM with Remove-SCVirtualMachine cmdlet and –Force option. That will delete the VM object in VMM but will not delete the VM itself. That VM will be discovered again but with different ID which will not be related to any Computer Tier, SC Service or Cloud Service. Basically will become standalone VM. You can change UserRole and Owner of that VM to your new subscription. That subscription should be able to see that VM on the Tenant Portal as standalone VM.

Advertisements

One thought on “Migrating VM Role from One Subscription to Another in Azure Pack

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s