The VCAC Database can be queried securely using the Dynamic Cloud Interface (ODATA/REST). 


This post will show you how to retrieve VirtualMachineProperties (the machines meta data) also known as “custom properties” using powershell & native http.

All scripts can be downloaded here

Load a VirtualMachine and its properties

# Name of the VM
$vmName = “vm1”

# Include DynamicOps Functions
. (Join-Path (Split-Path $script:MyInvocation.MyCommand.Path) \\DynamicOpsRestFunctions.ps1)

# Provide the Url – please note the escape charachter ` which is used prior to a $.
# $ is a special charachter in powershell so must be escaped or the filters will not work, no data will be returned 
$virtualMachinePropsUrl = “/VirtualMachines()?`$filter=VirtualMachineName eq ‘$vmName’&`$expand=VirtualMachineProperties”

# Json Data format is returned as a Dictionary with the char “d” always as the key.
# The key “d” then returns an array of objects, so to get the first one use [0]
$result = GetData($virtualMachinePropsUrl)

# Verify that the VM was found
if ( $result[“d”].Count -eq 0)
{
 Write-Error “Error: Machine ($vmName) was not found in the inventory.”
 Exit
}

# Print out the Custom Properties for $VmName
$vm = $result[“d”][0][“VirtualMachineProperties”]
$vmpProps = $result[“d”][0]
$vm



Example scripts: