vRealize Automation Managed VMs Report with Machine Owner’s ID

Featured

We were working on a requirement last week to pull a report of all vRealize Automation Managed Machines using PowervRA Module version 3.7.0 which supports vRealize Automation 7.6. While generating the report using a PowerShell script we noticed that the output was only showing the name of the Machine owner instead of the ID.

Then we started digging into the function Get-vRAResource of PowervRA Module and we noticed that the method which is used by function Get-vRAResource in PowervRA Module is /catalog-service/api/consumer/resourceViews

vRealize Automation API Method used by function Get-vRAResource in PowervRA

After checking the vRealize Automation Catalog Service API 7.6 documentation we realized that this method was deprecated in vRealize Automation 7.5 version and this method is similar to /catalog-service/api/consumer/resources method.

Method /api/consumer/resourceViews has been deprecated since version 7.5

We used our Good Old API building Platform Postman to do a side by side comparison of vRA API methods /catalog-service/api/consumer/resourceViews and /catalog-service/api/consumer/resources. If you’ll look at the output of both the methods closely, you’ll notice that the resourceViews methods returns only the Name of the Owner where as the resources methods returns an Array which includes the values of tenantName, ref, type & value out of which ref is the Machine Owner’s ID.

Side-by-Side Comparison of API Methods /api/consumer/resourceViews and /api/consumer/resources using Postman

Armed with all that information we prepared our script to pull resource Information of all vRA Managed Machines using PowervRA function Get-vRAResource and then we used the vRealize Automation API method /catalog-service/api/consumer/resources/{ResourceID} to get the Machine Owner’s ID of each Resource to generate our vRA Managed VMs report with Owner’s ID.

Script:

Set-ExecutionPolicy RemoteSigned

$cred = Get-Credential
$vRAFQDN = "vRA_FQDN"
$vRATenant = "TenantName"

#Connecting to vRA Server using PowervRA 3.7.0 Module
Connect-vRAServer -Server $vRAFQDN -Tenant $vRATenant -Username $cred.UserName -Password $cred.Password -IgnoreCertRequirements

#Fetching List of vRealize Automation Managed Virtual Machines
$filter = Get-vRAResource | where {$_.ResourceType -eq "Infrastructure.Virtual"}
$date = Get-Date -Format "yyyy-MM-dd-hh-mm-tt"
$print =  $filter | Select Data,Owners,ResourceId
$output = $print | Select @{Name="VMName";Expression={$_.Data.MachineName}}, @{Name="BusinessGroup";Expression={$_.Data.MachineGroupName}},`
@{Name="Owner";Expression={$_.Owners}}, @{Name="OwnersID";Expression={""}}, @{Name="ResourceID";Expression={$_.ResourceId}}, @{Name="ReservationName";Expression={$_.Data.MachineReservationName}},`
@{Name="vCPUs";Expression={$_.Data.MachineCPU}}, @{Name="Memory (MB)";Expression={$_.Data.MachineMemory}}, @{Name="Storage (GB)";Expression={$_.Data.MachineStorage}}
 
$output = $output | where {$_.VMName -ne $null}
 
$output | ft -AutoSize -Wrap

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $True }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')
 
$Body = @{
    username = $cred.UserName
    password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password))
    tenant = $vRATenant
} | ConvertTo-Json
 
#Generating API Bearer Token for vRA Login
 
$url = "https://" + $vRAFQDN
$tokenurl = $url + "/identity/api/tokens"
$token = Invoke-RestMethod -Method Post -Uri $tokenurl -Body $Body -Headers $headers -Verbose
$token = $token.id
$headers.Add('Authorization',"Bearer $token")
$printvalue = @{}
$i=0;

#Get Machine Owner's ID for each Managed Machine

foreach ($item in $output)
{
    $owneridurl = $url + "/catalog-service/api/consumer/resources/" + $item.ResourceId
    $ownersId = Invoke-RestMethod -Method Get -Headers $headers -uri $owneridurl -Verbose
    $item.OwnersID = $ownersId.owners.ref
    $printvalue[$i] = $item
    $i = $i + 1
}

$printvalue.Values | FT -AutoSize -Wrap
 
$printvalue.Values | Export-Csv C:\Users\Administrator\Desktop\vRAManagedMachineReport-$date.csv -NoTypeInformation

Output:

Sample Output

Just replace the vRA_FQDN and TenantName with the details of your vRA environment and supply the output file path to generate the report.

Happy Scripting!!

Export vRealize Automation Network Profile’s IP Ranges

Featured

We received a request to export the details of vRealize Automation Network Profile’s IP Ranges. We wrote a PowerShell script which uses PowervRA (3.6.0) module to extract the details of Network Ranges for each Network Profile.

Pre-requisites:

  • PowervRA 3.6.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server ‘vRA_Server/Portal_Address‘ -Username $cred.UserName -Password $cred.Password -Tenant ‘Tenant_Name‘ -IgnoreCertRequirements

$netids = Get-vRAExternalNetworkProfile
$out = @()
foreach ($netid in $netids)
{
$print = $netid | Select @{Name=”Name”;Expression={$_.Name}}, @{Name=”SubnetMask”;Expression={$_.SubnetMask}},`
@{Name=”BeginIPv4Address”;Expression={$_.DefinedRanges.beginIPv4Address}},`
@{Name=”EndIPv4Address”;Expression={$_.DefinedRanges.endIPv4Address}}
$out = $out + $print
}

$out | Export-Csv C:\Users\Administrator\vRANetProfileRanges.csv -NoTypeInformation
Disconnect-vRAServer -Confirm:$false

Output:

output

Just replace the vRA_Server/Portal_Address and Tenant_Name with the details of your vRA environment and supply the output file path.

Happy Scripting!!

 

Export vRealize Automation Business Group Details

We received a requirement to export the details of vRealize Automation Business Groups, to be more specific to extract the Business Group Ids, which is a very time consuming task if you have a large number of Business Groups in your environment. I wrote a PowerShell script which uses PowervRA (3.6.0) module to extract the details of Business Groups.

Requirements:

  • PowervRA 3.6.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server ‘vRA_Server/Portal_Address‘ -Username $cred.UserName -Password $cred.Password -Tenant ‘Tenant_Name‘ -IgnoreCertRequirements
$bgdetails = Get-vRABusinessGroup | Select Name, ID, Description
$bgdetails | Export-Csv C:\Users\Administrator\Desktop\BGDetails.csv -NoTypeInformation
Disconnect-vRAServer -Confirm:$false

Just replace the vRA_Server/Portal_Address and Tenant_Name with the details of your vRA environment and supply the output file path.

Happy Scripting!!