Super Simple RVTools Automation Script
Here is a very simple RVTools Automation script written in PowerShell. For anyone not familiar with RVTools, it’s a fantastic tool for managing your vSphere environment and available for free by Rob de Vey at RobWare.
RVTools is a tool that displays a ton of data about your vSphere environment from your vCenter Server. This script will automate that tool and retrieve data from as many vCenter servers as you want.
What is RVTools?
RVTools is a windows .NET 4.6.1 application which uses the VI SDK to display information about your virtual environments. In addition to pulling a lot of information about your VMware environment, RVTools can also update the VMware Tools installed inside each virtual machine to the latest version.
RVTools Automation Script Supports
- ESX Server 3x, 4x, 5x, 6x
- VirtualCenter (Windows) 2.5, 3.x, 4.x, 5.x, 6x
- VirtualCenter Appliance 5.x, 6.x
RVTools Automation Script Collects
- VMs
- CPU
- Memory
- Disks
- Partitions
- Network
- Floppy drives
- CD drives
- Snapshots
- VMware tools
- Resource pools
- Clusters
- ESX hosts
- HBAs
- NICs
- Switches
- Ports
- Distributed Switches
- Distributed Ports
- Service consoles
- VM Kernels
- Datastores
- multipath info
- license info
- health checks
You can download the latest version here.
The script has been tested with PowerShell version 3 and above but please leave a comment below if you are using this script on an older version of PowerShell so I can update the notes here.
It is important to note you do not need to have PowerCLI installed but I highly recommend you install PowerCLI and use all the abilities it brings to your vSphere environment.
RVTools Automation Script Details
The RVtools automation script starts with version information and normal comment based help which could use additional information if you choose to add it.
Around line 20 I set some variables for the location of RVTools. This will need to be changed if you have RVTools in a different location.
I like to run all my scripts from the same location of the script file. The Set-Location changes my working directory to this location and all output will go into a directory off this point.
The Set Parameters section is the key location for the script. In this location I read in the CSV list of VC names or Ips, the User ID to login into the VC server, and the encrypted password.
To encrypt the password, RVTools has a very simple Password Encryption program included where you just enter your password and then copy the encrypted version into the CSV file.
The CSV File Contents
- VCServer,User,EncryptedPassword
- Server220,vsphere.local\administrator,_RVToolsPWgdiQ6seCi+FV3NFV7w=
- Server223,vsphere.local\administrator,_RVToolsPWDNdgy/64LxCcbi+FV3NFV7w=
- 192.168.1.220,vsphere.local\administrator,_RVToolsPW4Ehxgy/63k8Ci+3NFV7w=
The XlsDir1 variable sets the directory where you want the reports saved to.
The ForEach loop will read in each line in the CSV file and assign each item to a variable using the same name in the header of the CSV file. Also within the loop, I also set a variable for the current date and time and add it to a new variable (XlsFile1) along with the VC name. This will become the first entry output CSM file.
All the Write-Host commands are just providing a little information to the screen so you know what servers connect OK and which do not.
The Arguments variable is appended with all the information the RVTools.exe program needed to run in the command line. Notice I have the VC name, User, Password being used to make the VC connection.
The Process line will run the program and put the results in the Process variable to be checked in the following line for errors.
The last If-Else loop is a simple if else looking for an exit code of -1. IF found, an error is printed on the screen but if 0, then a success is printed.
That’s it, very simple. Feel free to modify anyway you like.
RVTools Automation Script
# =============================================================================================================
# Script: Get-RVTools.ps1
# Version: 1.1
# Date: 7/1/2019
# By: TJ Totland, IBM
# =============================================================================================================
<#
.SYNOPSIS
With this RVTools Automation script, you can start the the RVTools export all to xlsx function for multiple vCenter servers.
.DESCRIPTION
With this script you can start the the RVTools export all to xlsx function for multiple vCenter servers.
.EXAMPLE
.\RVToolsBatchMultipleVCs.ps1
#>
# Set RVTools path
[string] $RVTools = "C:\Program Files (x86)\Robware\RVTools\RVTools.exe"
Set-Location $PSScriptRoot # Changes directory to the same directory the script is running from
# ----------------------------------------------------------
# Set parameters (additional parameters in the For-Each Loop
# ----------------------------------------------------------
$CSVFile = import-csv “.\ServerList.csv”
[string] $XlsxDir1 = ".\Reports\"
ForEach($CSVItem in $CSVFile) {
# -----------------------------------------------------
# Set parameters
# -----------------------------------------------------
$Datetime = get-date -format `yyyyMMdd-HHmm.ss
$VCServer = $CSVItem.VCServer
$User = $CSVItem.User
$EncryptedPassword = $CSVItem.EncryptedPassword
[string] $XlsxFile1 = $Datetime + "-" + $VCServer + "_RVTools-Export.xlsx" # Start cli of RVTools
Write-Host "$VCServer at $Datetime : Export Started" # -ForegroundColor DarkYellow
# Adds all the arguments into a variable to be added to RVTools.exe command
$Arguments = "-u $User -p $EncryptedPassword -s $VCServer -c ExportAll2xlsx -d $XlsxDir1 -f $XlsxFile1 -DBColumnNames -ExcludeCustomAnnotations"
# Runs the RVTools process with all arguments from above
$Process = Start-Process -FilePath "$RVTools" -ArgumentList $Arguments -NoNewWindow -Wait -PassThru
# Checks for Error and writes to Host Screen if problem
if($Process.ExitCode -eq -1) {
Write-Host "$VCServer at $Datetime : Connection FAILED!" -ForegroundColor Red
# exit 1
} else {
Write-Host "$VCServer at $Datetime : Export Successful" -ForegroundColor DarkYellow
}
}
Conclusion
Please let me know if this script was helpful to you or if you have any changes you thing I should add to the RVTools automation script. The purpose was to keep the script easy and small, but I would be happy to include your ideas into a new script and post it in a future article.
If you want to receive more scripts to help you automate your environment, signup for our email list and you will get updated when I create new posts.
There is no reason you should be running your RVTools reports manually. Use this RVTools automation script and make your life easier and spend your time doing other things!
1 Response