Home > Blogs > VMware PowerCLI Blog

Automating the creation of vCD Provider VDCs

Posted by
Alan Renouf
Technical Marketing

Following my previous post where I showed how easy and quick it was to create Organizations, Users and Organization VDC’s I thought it would be good to take it one step further or in this case backwards, to create the items we created in the last post we must first need a Provider VDC, we need this to provide the resources to the Organization VDC.

The script detailed further in this post can be used to create a Provider VDC, to do this we will obviously need to provide resources from a vCenter, for this to be done we need to connect to both the Cloud Infrastructure and the vSphere Infrastructure which is not an issue for PowerCLI.

In the script I have assumed that all hosts in the cluster will have access to the same shared storage and that this is the storage which will be used in the Provider VDC, I have also assumed that we will be using a Cluster to back our Provider VDC and not a resource pool… Although technically this is the root resource pool anyway, to learn more about the root resource pool make sure you read William Lams great introductory posts to the API here.

Creating a Provider VDC

The following script can be used to create a Provider VDC, it is shown as an example and not a complete function which provides all parameters and functions needed in a more complex situation:

Function New-ProviderVDC {

    Param (
    Process {

        $vcloud = $DefaultCIServers[0].ExtensionData
        $admin = $vcloud.GetAdmin()
        $ext = $admin.GetExtension()
        $ProvidervDCDetails = New-Object VMware.VimAutomation.Cloud.Views.VMWProviderVdc
        $ProvidervDCDetails.Name = $Cluster
        $VC = $ext.GetVimServerReferences()
        $VimServer = $vc.VimServerReference[0]
        $ProvidervDCDetails.VimServer = $VimServer
        $ProvidervDCDetails.Description =$Description
        $ProvidervDCDetails.IsEnabled = $Enabled
        $Datastorerefs = New-Object VMware.VimAutomation.Cloud.Views.VimObjectRefs
        $Datastores = @()
        Foreach ($DS in (Get-Cluster $Cluster | Get-VMHost | Select -First 1 | Get-Datastore | Where {$_.Extensiondata.Summary.MultipleHostAccess})) {
            $Datastore = New-Object VMware.VimAutomation.Cloud.Views.VimObjectRef
            $Datastore.VimServerRef = $VimServer
            $Datastore.MoRef = (($DS).Id).Trim("Datastore-")
            $Datastore.VimObjectType = "DATASTORE"
            $Datastores += $Datastore
        $Datastorerefs.VimObjectRef = $Datastores
        $ProvidervDCDetails.DataStoreRefs = $Datastorerefs
        $RPrefs = New-Object VMware.VimAutomation.Cloud.Views.VimObjectRefs
        $RPrefs.VimObjectRef = @(New-Object VMware.VimAutomation.Cloud.Views.VimObjectRef)
        $RPrefs.VimObjectRef[0].VimServerRef = $VimServer
        $RPrefs.VimObjectRef[0].MoRef = ((Get-Cluster $Cluster | Get-ResourcePool Resources).ExtensionData).Moref.Value
        $RPrefs.VimObjectRef[0].VimObjectType = "RESOURCE_POOL"
        $ProvidervDCDetails.ResourcePoolRefs = $RPrefs
        #If HWVersion is not defined then use 7 by default
        If ($HWVersion) {
            $HWVer = "vmx-0$($HWVersion)"
        } Else {
            $HWVer = "vmx-07"
        $ProvidervDCDetails.HighestSupportedHardwareVersion = $HWVer


Running the script

As mentioned before, we must fist connect to both the Cloud Infrastructure as well as the Virtual Infrastructure, once this has been done we can use the above function to create our provider VDC by passing it the cluster information and the hardware version:

# Adding PowerCLI vCD snapin
if (!(get-pssnapin -name VMware.VimAutomation.Cloud -erroraction silentlycontinue)) {
    add-pssnapin VMware.VimAutomation.Cloud

# Adding PowerCLI snapin
if (!(get-pssnapin -name VMware.VimAutomation.Core -erroraction silentlycontinue)) {
    add-pssnapin VMware.VimAutomation.Core

# Connectiong to CI and VI
Connect-VIServer myvc -User Administrator -Password vmware
Connect-CIServer myvcd -User Administrator –Password P@ssw0rd

# Create the Provider VDC
New-ProviderVDC -Cluster Cluster01 -Description "A Description for my cluster" -Enabled -HWVersion 7

The Result

A shiny new Provider VDC

DataStoreRefs                   : VMware.VimAutomation.Cloud.Views.VimObjectRefs
ResourcePoolRefs                : VMware.VimAutomation.Cloud.Views.VimObjectRefs
VimServer                       : {VC01}
HostReferences                  : VMware.VimAutomation.Cloud.Views.VMWHostReferences
HighestSupportedHardwareVersion : vmx-07
Status                          : 0
ComputeCapacity                 : VMware.VimAutomation.Cloud.Views.RootComputeCapacity
StorageCapacity                 : VMware.VimAutomation.Cloud.Views.ProviderVdcCapacity
AvailableNetworks               : VMware.VimAutomation.Cloud.Views.AvailableNetworks
Capabilities                    :
Vdcs                            :
IsEnabled                       : True
NetworkPoolReferences           : VMware.VimAutomation.Cloud.Views.NetworkPoolReferences
Name                            : Cluster01
Id                              : urn:vcloud:providervdc:b2746976-c674-45bc-89b1-c6c38bad42f7
Description                     : A Description for my cluster
Tasks                           : VMware.VimAutomation.Cloud.Views.TasksInProgress
Client                          : VMware.VimAutomation.Cloud.Views.CloudClient
Href                            :
Type                            : application/vnd.vmware.admin.vmwprovidervdc+xml
Link                            : {, , , …}
AnyAttr                         : {xsi:schemaLocation}
VCloudExtension                 :

Or as can be seen from the GUI:


Of course the more attentive of you will notice the system alerts on the status, this is because we now need to prepare the hosts in this Provider VDC but that’s a subject for another blog post !

Get notification of new blog postings and more by following VMware PowerCLI on Twitter: @PowerCLI

This entry was posted in Advanced on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

2 thoughts on “Automating the creation of vCD Provider VDCs

  1. Perry Bright

    What if I do want to place the Provider vDC on a Resource Pool in the cluster and not on the Cluster itself? For instance GOLD, SILVER, and BRONZE Resource Pools.
    Also, I want to add specific Datastores to the GOLD and then different Datastores to SILVER and so on.
    Can you deminstrate how to do that as well?

  2. Suyog Uttekar

    This is Suyog, we tried executing the above script in pur vcloud environment. It works fine while we have query are this functions and parameter dynamically created on-demand and once connection is closed we have to again type for function & paramter for the command line to be executed.

    Are there any way we have store the functions and parameter in one place on the server and run the command to get the necessary result.

    Suyog Uttekar


Leave a Reply

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