SCVMM: mit Powershell Teil 1

Ich habe gerade das Glück etwas mehr mit Powershell und System Center Virtual Machine Manager 2012 (SCVMM, RC) zu arbeiten. Daher werde ich hier wieder ein paar Codesnippsel posten, um bestimmte Funktionen zu automatisieren:

die erste Funktion soll eine neue Cloud für Hyper-V erzeugen . Zusätzlich wird ein neue Rolle für diese Cloud angelegt, die nur VMs verwalten darf.

#creates a new cloud and a corresponding usergroup
function createCloud([string]$name,[string]$hostgroupname)
{
   #retrieving first GUID for creating the new cloud
     $job= ([System.Guid]::NewGuid().toString())
   #define Cloud limitations (here: no limit)
     Set-SCCloudCapacity -JobGroup $job -UseCustomQuotaCountMaximum $true -UseMemoryMBMaximum $true -UseCPUCountMaximum $true -UseStorageGBMaximum $true -UseVMCountMaximum $true
   #setting the used network (here: the network has the same name as the cloud)
     $resources = @()
     $resources += Get-SCLogicalNetwork -Name $Name
   #defining that the cloud can be used on hyper-v server
     $addCapabilityProfiles = @()
     $addCapabilityProfiles += Get-SCCapabilityProfile -Name "Hyper-V"
   #adding the settings to the cloud with the defined GUID
     Set-SCCloud -JobGroup $job -RunAsynchronously -AddCloudResource $resources -AddCapabilityProfile $addCapabilityProfiles
   #adding the cloud to the hostgroup
     $hostGroups = @()
     $hostGroups += Get-SCVMHostGroup -Name $hostgroupname
   #creating the cloud and the rest from the first job :-)
     New-SCCloud -JobGroup $Job -VMHostGroup $hostGroups -Name $Name -RunAsynchronously

#creating the usergroup
   #GUID for the second job
     $job= ([System.Guid]::NewGuid().toString())
   #the roleis for the newly created cloud
     $scopeToAdd = @()
     $scopeToAdd += Get-SCCloud -name $name
   #the user of this role can start, stop and shutdown virtual machines in the cloud and start a remote control
     Set-SCUserRole -JobGroup $job -AddScope $scopeToAdd -Permission @("RemoteConnect", "Shutdown", "Start", "Stop") -ShowPROTips $false
     $cloud = Get-SCCloud -Name $name
   #add all settings to the role
     Set-SCUserRoleQuota -Cloud $cloud -JobGroup $job -QuotaPerUser -UseCPUCountMaximum -UseMemoryMBMaximum -UseStorageGBMaximum -UseCustomQuotaCountMaximum -UseVMCountMaximum
   #create the role with the job guid
     New-SCUserRole -Name $name -UserRoleProfile "SelfServiceUser" -Description "" -JobGroup $job
}

Die Funktion kann einfach per


createCloud "MeineCloud" "Alle Hosts"

aufgerufen werden.

This entry was posted in Deutsch, Hyper-V, Powershell, System Center, Virtual Machine Manager and tagged , . Bookmark the permalink.

Leave a Reply