Created
June 27, 2016 08:17
-
-
Save chelnak/cd89135a555a00246e16520681b408cf to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment