-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetvRADeployments.ps1
More file actions
32 lines (25 loc) · 988 Bytes
/
getvRADeployments.ps1
File metadata and controls
32 lines (25 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
.SYNOPSIS
Code sample on how to get deployments from VMware vRA SaaS or On-Prem via REST
.DESCRIPTION
Code sample on how to get deployments from VMware vRA SaaS or On-Prem via REST
.NOTES
Website: www.amikkelsen.com
Author: Anders Mikkelsen
Creation Date: 2022-01-21
#>
function Get-vRARestData($vRAUrl, $apiUrl, $token) {
# Get BearerToken
$bearerUrl = $vRAUrl + "/iaas/api/login"
$body = "{`"refreshToken`": $token}"
$bearerToken = Invoke-RestMethod $bearerUrl -ContentType "application/json" -Body $body -Method 'POST'
# Get data
$uri = $vRAUrl + $apiUrl
$response = Invoke-RestMethod $uri -Headers @{'Authorization' = "Bearer $($bearerToken.token)" } -Method 'GET'
Return $response
}
$vRAUrl = "https://api.mgmt.cloud.vmware.com"
$apiUrl = "/deployment/api/deployments"
$token = "<vRA API token -- NOT bearer token>"
$result = Get-vRARestData -vRAUrl $vRAUrl -ApiUrl $apiUrl -token $token
$result | ConvertTo-Json