Using Job Groups in VMM Scripts

 

Updated: May 13, 2016

Applies To: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

The JobGroup parameter uses an identifier to group a series of commands into a single job group that will run as a set just before the final command that includes the same job group identifier runs.

The JobGroup parameter requires a GUID, which you must obtain before setting the value for the JobGroup. The following command demonstrates how to generate a globally unique identifier (GUID) and store it in the $JobGroupID variable:

$JobGroupID = [Guid]::NewGuid().ToString()  

To include subsequent commands in the job group, set the JobGroup parameter for that command to the same value. For example, all commands that include -JobGroup $JobGroupID will not run until just before the final command that also includes -JobGroup $JobGroupID.

The following example demonstrates how to use JobGroup in a script. The New-SCVirtualDiskDrive cmdlet in the third line queues the work to be done by New-SCVirtualDiskDrive, but does not run until just prior to the New-SCVirtualMachine cmdlet. New-SCVirtualMachine is the last command that includes JobGroup and initiates work, bundling in any previously queued work. In this case, that means running New-SCVirtualDiskDrive and then New-SCVirtualMachine.

  
# Generate a GUID for the JobGroupID variable.  
$JobGroupID = [Guid]::NewGuid().ToString()  
  
$VHD = Get-SCVirtualHardDisk -VMMServer "VMMServer01.Contoso.com" | where {$_.Location -eq "\\LibServer01.Contoso.com\MSSCVMMLibrary\VHDs\Blank Disk - Large.vhd"}  
  
# This is the first cmdlet that uses the JobGroup variable.  
New-SCVirtualDiskDrive -IDE -Bus 0 -LUN 1 -JobGroup $JobGroupID -VirtualHardDisk $VHD  
  
$HWProfile = Get-SCHardwareProfile | where {$_.Name -match "NewHWProfile01"}  
$VMHost = Get-SCVMHost -ComputerName "VMHost03"  
  
# This is the last cmdlet that uses the JobGroup variable, which indicates that  
# New-SCVirtualDiskDrive should run just prior to the following command.  
New-SCVirtualMachine -Name "VM10" -Description "New Virtual Machine VM10" -JobGroup $JobGroupID -VMMServer "VMMServer01.Contoso.com" -Owner "Contoso\Katarina" -VMHost $VMHost -Path "D:\VirtualMachinePath" -HardwareProfile $HWProfile -RunAsynchronously -StartAction NeverAutoTurnOnVM -StopAction SaveVM  
  

You can use the JobGroup parameter with the following cmdlets:

  • Add-SCLibraryServer

  • Add-SCLibraryShare

  • Add-SCVMHostNetworkAdapter

  • Compress-SCVirtualDiskDrive

  • Convert-SCVirtualDiskDrive

  • Copy-SCStorageVolume

  • Disable-SCRunAsAccount

  • Enable-SCRunAsAccount

  • Expand-SCVirtualDiskDrive

  • Get-SCVMHostRating

  • Grant-SCResource

  • Install-SCVMHostCluster

  • Mount-SCStorageDisk

  • Move-SCVirtualHardDisk

  • Move-SCVirtualMachine

  • Move-SCVMHostGroup

  • New-SCCloud

  • New-SCHardwareProfile

  • New-SCP2V

  • New-SCRunAsAccount

  • New-SCUserRole

  • New-SCV2V

  • New-SCVirtualDiskDrive

  • New-SCVirtualDVDDrive

  • New-SCVirtualMachine

  • New-SCVirtualNetwork

  • New-SCVirtualNetworkAdapter

  • New-SCVirtualScsiAdapter

  • New-SCVMTemplate

  • Register-SCStorageLogicalUnit

  • Register-SCVirtualMachine

  • Remove-SCCloud

  • Remove-SCCustomPropertyValue

  • Remove-SCUserRole

  • Remove-SCVirtualDiskDrive

  • Remove-SCVirtualDVDDrive

  • Remove-SCVirtualHardDisk

  • Remove-SCVirtualNetwork

  • Remove-SCVirtualNetworkAdapter

  • Remove-SCVirtualScsiAdapter

  • Remove-SCVMCheckpoint

  • Remove-SCVMHostNetworkAdapter

  • Revoke-SCResource

  • Set-SCApplication

  • Set-SCApplicationSetting

  • Set-SCBaseline

  • Set-SCCloud

  • Set-SCCloudCapacity

  • Set-SCCustomPropertyValue

  • Set-SCHardwareProfile

  • Set-SCLibraryServer

  • Set-SCRunAsAccount

  • Set-SCUserRole

  • Set-SCUserRoleQuota

  • Set-SCVirtualCOMPort

  • Set-SCVirtualDiskDrive

  • Set-SCVirtualDVDDrive

  • Set-SCVirtualFloppyDrive

  • Set-SCVirtualHardDisk

  • Set-SCVirtualMachine

  • Set-SCVirtualNetwork

  • Set-SCVirtualNetworkAdapter

  • Set-SCVirtualScsiAdapter

  • Set-SCVMHost

  • Set-SCVMHostCluster

  • Set-SCVMHostGroup

  • Set-SCVMHostNetworkAdapter

  • Set-SCVMTemplate

  • Start-SCUpdateRemediation

  • Unregister-SCStorageLogicalUnit

VMM Cmdlet Help Topics

Show: