Create VMM Clouds in bulk with PowerShell
As you might remember from my previous blog post I’m working now on a Hyper-V migration project where I couldn’t reuse the old VMM server. So besides re-creating virtual networks in bulk with Powershell I also had to re-create the clouds defined in the old VMM in bulk with powershell.
The idea is the following:
- Export all Clouds from the old VMM to a csv file
- Import all cloud to the new VMM from the csv file
So first of all we need to export our Clouds to a CSV by running the following Powershell Commandlet:
[xml]
Get-SCCloud |Export-Csv -Path C:\Temp\cloud.csv
[/xml]
Now that we have the CSV file we can use it in our new environment to automatically create in bulk the same Clouds.
You can download the script here.
The script will read through the CSV, get all the names and create new clouds based on the settings you define in the script like: capacity, hostgroup, virtual network, storage, etc:
[xml]
#Variables
$CloudCSV = IMPORT-CSV C:\Tmp\Cloud.csv
$CloudDescription = ”
$hostGroups = @()
$HostGroups = Get-SCVMHostGroup -Name “All hosts”
$resources = @()
$LogicalNetwName = Get-SCLogicalNetwork -Name “Contoso – Reference – Network”
$Storage = Get-SCStorageClassification -Name “Remote Storage”
$resources += $LogicalNetwName
$readonlyLibraryShares = @()
$readonlyLibraryShares += Get-SCLibraryShare | where {$_.Name -match “VMLibrary”}
#Loop through all the clouds in the CSV and create a new cloud for each line
Foreach ($Cloud in $CloudCSV){
$CloudName = $($Cloud.Name)
#Create a new job guid per cloud
$Guid = [System.Guid]::NewGuid()
Set-SCCloud -JobGroup $Guid
Set-SCCloudCapacity -JobGroup $Guid -UseCustomQuotaCountMaximum $true -UseMemoryMBMaximum $true -UseCPUCountMaximum $true -UseStorageGBMaximum $true -UseVMCountMaximum $true
$resources += Get-SCPortClassification -Name “Guest Dynamic IP”
$resources += Get-SCPortClassification -Name “High bandwidth”
$resources += Get-SCPortClassification -Name “Low bandwidth”
$resources += $Storage
Set-SCCloud -JobGroup $Guid -RunAsynchronously -AddCloudResource $resources -AddReadOnlyLibraryShare $readonlyLibraryShares
New-SCCloud -JobGroup $Guid -VMHostGroup $hostGroups -Name $CloudName -Description $CloudDescription -RunAsynchronously
}
[/xml]
Hope this helps,
Alex
Leave a comment