chelnak
6/27/2016 - 8:17 AM

Example script to demonstrate how to submit multiple vRA catalog item requests with PowervRA from a predefined list. The example submits ea

Example script to demonstrate how to submit multiple vRA catalog item requests with PowervRA from a predefined list.

The example submits each request as a seperate PSJob. The status of each job can be monitored via the vRA web console and by using Get-Job.

<#

    Example script to demonstrate how to submit multiple vRA catalog item requests 
    from a predefined list.

    The example submits each request as a seperate PSJob. The status of each job can be
    monitored via the vRA web console and by using Get-Job.

#>

Import-module -Name PowervRA

Connect-vRAServer -Server [server] -Tenant [tenant] -Credential (Get-Credential)

$RHEL66CatalogItemId = "8a91b3b0-aeee-4925-b8bb-4b0d83509b01"

$Data = Import-CSV -Path .\requestData.csv

foreach ($Request in $Data) {

    # --- Convert the JSON string to an object
    $Object = (Get-vRAConsumerCatalogItemRequestTemplate -Id $RHEL66CatalogItemId | ConvertFrom-JSON)

    # ---Build the Request
    $RequestProperties = $Object.data.RHEL66.data    
    $RequestProperties.Hostname = $Request.Hostname
    $RequestProperties.cpu = $Request.cpu
    $RequestProperties.memory = $Request.memory

    Write-Output "Submitting request for virtual machine: $($Request.Hostname)"

    # --- Submit the request using the Wait switch to monitor the status of the request
    Start-Job -Name $Request.Hostname -ScriptBlock {

        param($Global:vRAConnection)
        
        ($Using:Object | ConvertTo-JSON -Depth 100) | Request-vRAConsumerCatalogItem -Wait -Confirm:$false
        
        
        } -ArgumentList $Global:vRAConnection | Out-Null
    
    # --- Sleep so we don't overload the API
    Start-Sleep -Seconds 5

}

# --- Disconnect the session
Disconnect-vRAServer -Confirm:$false