VMware:  Automating Aria automation VM Onboarding with PowerShell

VMware by Broadcom Aria Automation offers powerful automation capabilities, but sometimes, a custom script can further streamline your processes.

In this blog post, we’ll walk through a PowerShell script designed to automate the onboarding of VMs into a specific Aria automation project and change the resource owner.

Overview:

The script performs the following tasks:

  1.       Connects to the vRA server.
  2.       Imports a list of VMs from a CSV file.
  3.       Retrieves the necessary project and VM details from vRA.
  4.       Construct a JSON request to onboard each VM.
  5.       Send the request to the vRA API to complete the onboarding process.

Prerequisites:

Before running the script, ensure you have the following:

  •           PowerShell installed on your machine.
  •           vRA PowerCLI module installed.
  •           Access to the vRA server with appropriate permissions.
  •           A CSV file containing the list of VMs to onboard.

You can generate a list of discovery VMs in Aria automation by SSH to the vRA node as root and connect to the vRA DB: 

vracli dev psql 

Type yes for the session to be recorded                  

Navigate to the catalog-db

template1=#: \c catalog-db

Run the below query to list all VM resources with their name and origin status: 

catalog-db=#: \copy (select name,state,origin from dep_resource where type=’Cloud.vSphere.Machine’ AND origin=’DISCOVERED’) TO /tmp/vm_onbording.csv CSV HEADER;

After running the query, a CSV file similar to this below will be generated:

name |   state     |  origin

—————+———–+———–

VM1         | ACTIVE    | DISCOVERED

VM2         | ACTIVE    | DISCOVERED

VM3         | ACTIVE    | DISCOVERED

The file will be saved on docker data, so use the Linux find command to find the CSV file.

find /  -name vm_onbording.csv

Set up the necessary variables in the # User Variables section of the script, including the Aria Automation server details, user credentials, project name, and CSV file path, and then the job will be done.

The script can be found on my GitHub here.

This approach saves time and reduces the potential for human error, ensuring a more efficient and reliable VMs management process. Happy automating!

 

Leave a Reply

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