How to Associate a Cloud to Multiple Virtual Machines in VMM 2012 R2 Via PowerShell #VMM #SysCtr #SCVMM #PowerShell

Hello folks,

As you know that in System Center Virtual Machine 2012 R2, we can create “Clouds” SmallCloudas pools of delegated resources that abstract the underlying physical fabric such as compute, network and storage. We can create multiple Clouds for varying business units needs or tenants, and then present each Cloud with a defined capacity that we can increase later, decrease or customize as needed. In this manner, Virtual Machine Manager provide us with a lot of flexibility for mapping our datacenter capacity to changing business requirements while not exposing the full fabric capacity details to customers.

In SCVMM in order to deploy a service to a cloud, you must have the following requirements in place:

Service Templates that are configured through the use of many VMM resources such as virtual hard disks, VM Templates, Guest OS profiles, Hardware profiles, and other VMM library resources. The service template allows us to configure how many Virtual Machines are initially deployed as part of the service deployment, then configure the applications to be installed at deployment time.

For example when you deploy a multi-tier application to a tenant or business unit, the virtual machines that belong to this service will be associated to a Cloud.

The following figure will illustrate the picture:

AssociateCloud_VMM07

The first question is what if you already have virtual machine that was manually deployed without Service Template, would you be able to associate it to a Cloud?

The answer is YES! Smile

How to do it?

You can browse to the VM and follow the steps below:

VM not associated to a cloud:

AssociateCloud_VMM02

VM associated to a cloud:

AssociateCloud_VMM03

The second question is what if you have 100 virtual machines that was manually deployed without Service Template, would you still be able to associate them to a Cloud?

The answer is YES!

How to do it?

Well same as we did above… very simple.

Really Surprised smile NOOOO!

So I have created the following simple PowerShell tool that will save you 400 clicks on your mouse, 4 clicks per VM Open-mouthed smile.

<#
.SYNOPSIS
Set the Associate Cloud to Multiple Virtual Machines.

.DESCRIPTION
This script will set or remove cloud association for all Virtual Machines to a specific Tenant and Host Group.

.NOTES
File Name : Set-AssociateCloud.ps1
Author      : Charbel Nemnom
Version    : 1.0
Requires  : PowerShell Version 3.0 or above
OS           : Windows Server 2012 or above with System Center Virtual Machine Manager 2012 R2

.LINK
To provide feedback or for further assistance please visit:
https://charbelnemnom.com

.EXAMPLE
./Set-AssociateCloud -TenantCloudName <CloudProvider> -HostGroupName <Hosts>
This example will set the cloud association to all virtual machines for a specific Tenant and Host Group.
.EXAMPLE
./Set-AssociateCloud -TenantCloudName <CloudProvider> -HostGroupName <Hosts> -AssociateCloud No
This example will remove the cloud association from all virtual machines for a specific Tenant and Host Group.
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[Alias(‘CloudName’)]
[String]$TenantCloudName,

[Parameter(Mandatory=$true)]
[Alias(‘GroupName’)]
[String]$HostGroupName,

[ValidateSet(“Yes”,”No”)]
[String]$AssociateCloud=’Yes’
)

$Cloud = Get-SCCloud -VMMServer localhost | where {$_.Name -eq $TenantCloudName}
$hostGroups = Get-SCVMHostGroup -Name $HostGroupName
Foreach ($hostGroup in $hostGroups.AllChildHosts)
{
$VMs = Get-SCVirtualMachine -VMMServer localhost -VMHost $HostGroup
foreach ($VM in $VMs)
{
If($AssociateCloud -eq ‘Yes’)
{
Set-SCVirtualMachine -VM $VM.Name -Cloud $Cloud
}
Else
{
Set-SCVirtualMachine -VM $VM.Name -RemoveFromCloud
}
}
}

If you need to associate all virtual machines to a specific tenant and host group, you can run the following cmdlet:

AssociateCloud_VMM04

AssociateCloud_VMM05

The default parameter to Associate Cloud is Yes, if you want to dissociate a Cloud from all Virtual Machines, then you need to add the parameter –AssociateCloud No

AssociateCloud_VMM06

AssociateCloud_VMM01

Hope this helps!

Until then… see you in the Cloud Smile

Cheers,
/Charbel

About Charbel Nemnom 311 Articles
Charbel Nemnom is a Microsoft Cloud Consultant and Technical Evangelist, totally fan of the latest's IT platform solutions, accomplished hands-on technical professional with over 15 years of broad IT Infrastructure experience serving on and guiding technical teams to optimize performance of mission-critical enterprise systems. Excellent communicator adept at identifying business needs and bridging the gap between functional groups and technology to foster targeted and innovative IT project development. Well respected by peers through demonstrating passion for technology and performance improvement. Extensive practical knowledge of complex systems builds, network design and virtualization.

Be the first to comment

Leave a Reply