VMM: Things to do with VM Custom Properties

One of our Beta users recently asked about programmatically setting some of the 10 custom properties for VMs so that it displays some useful information about the VM in the Host view of the VMM Administrator Console. For example:

  •  Location of VHD on Channel 0
  •  Virtual network on network adapter 0

One of the sample scripts in the soon-to-be-released Scripting Guide shows how to set a custom property on your VM, in this case, whether it needs VM additions

##################################################################################

# Connect to VMM server

##################################################################################

 

# Substitute the name of your VMM server and domain in this command:

$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

 

##################################################################################

# Find all the virtual machines without additions and update their custom property ##################################################################################

 

$VMs = @(Get-VM)

$VMsWithoutAdditions = @($VMs | where {$_.HasVMAdditions -eq $false})

 

if ($VMsWithoutAdditions -ne 0)

{

    Write-Host -ForegroundColor Yellow "UPDATE CUSTOM PROPERTY"

}

 

foreach ($VM in $VMsWithoutAdditions)

{

    Write-Host "Setting Custom10 property as `"Needs VM additions`" on VM", $VM.Name, "..."

    $UpdatedVM = Set-VM -VM $VM -Custom10 "Needs VM additions"

}

Here is how you would populate Custom1 and Custom2 with the location of the VHD on channel 0 and the Virtual Network on NIC adapter 0:

$vm = get-vm -Name "My VM"
$vm | set-vm -Custom1 $vm.VirtualHardDisks[0].Location -Custom2
$vm.VirtualNetworkAdapters[0].VirtualNetwork }

The following script would populate these properties for all VMs managed by
SCVMM:

$vms = get-vm
foreach ($vm in $vms) $vm | set-vm -Custom1
$vm.VirtualHardDisks[0].Location -Custom2
$vm.VirtualNetworkAdapters[0].VirtualNetwork }