Using PowerCLI to export vCloud Director policy settings

Posted by
Alan Renouf
Technical Marketing

Each Organization in vCloud Director has its own policy settings, these are defined when setting up the organization and can be altered through the  vCloud GUI, these define both the vApp lease periods and quotas of VMs which can be running or stored in the Organization.

This can be viewed by right clicking the Organization and selecting Properties and then selecting the Policies tab as below.


Recently I was asked by a customer if there was any way to retrieve this information for each Organization in his very populated vCloud Environment, understandably he did not want to right click each Organization and note the information, this could take a long time.

Luckily with PowerCLI 5.0.1 and the vCloud Director Snapin we can use the Get-Org and some custom selections to gain this information with a quick and easy script:

Get-Org | Foreach {
    $_ | Select Name,
    @{N="vAppMaxRuntimeLeaseDays";E={(New-Timespan -Seconds $_.ExtensionData.Settings.vAppLeaseSettings.DeploymentLeaseSeconds).TotalDays}},

    @{N="vAppMaxStorageLeaseDays";E={(New-Timespan -Seconds $_.ExtensionData.Settings.vAppLeaseSettings.StorageLeaseSeconds).TotalDays}},
    @{N="vAppStorageCleanup";E={If ($_.ExtensionData.Settings.vAppLeaseSettings.DeleteOnStorageLeaseExpiration) { "Delete" } Else { "Move"}}},

    @{N="TemplateMaxStorageLeaseDays";E={(New-Timespan -Seconds $_.ExtensionData.Settings.vAppTemplateLeaseSettings.StorageLeaseSeconds).TotalDays}},
    @{N="TemplateStorageCleanup";E={If ($_.ExtensionData.Settings.vAppTemplateLeaseSettings.DeleteOnStorageLeaseExpiration) { "Delete" } Else { "Move"}}},



When run this we will see the results of each Organization within the vCD environment, this is easily exportable using PowerShells built in cmdlets such as Export-CSV or Export-CLiXml or ConvertTo-Html.

Name                        : Tenant01
vAppMaxRuntimeLeaseDays     : 7
vAppMaxStorageLeaseDays     : 30
vAppStorageCleanup          : Move
TemplateMaxStorageLeaseDays : 90
TemplateStorageCleanup      : Move
RunningVMQuota              : 9
StoredVMQuota               : 11

Name                        : Tenant02
vAppMaxRuntimeLeaseDays     : 1
vAppMaxStorageLeaseDays     : 1
vAppStorageCleanup          : Delete
TemplateMaxStorageLeaseDays : 7
TemplateStorageCleanup      : Delete
RunningVMQuota              : 3
StoredVMQuota               : 5

Name                        : Tenant03
vAppMaxRuntimeLeaseDays     : 365
vAppMaxStorageLeaseDays     : 365
vAppStorageCleanup          : Move
TemplateMaxStorageLeaseDays : 365
TemplateStorageCleanup      : Move
RunningVMQuota              : 950
StoredVMQuota               : 1000


Leave a Reply

Your email address will not be published. Required fields are marked *