Automation
How To Automate RVTools With Scripts And Scheduled Tasks

How To Automate RVTools With Scripts And Scheduled Tasks

If you’re a regular user of RVTools and spent any time reading the very comprehensive documentation you may have already discovered the additional utilities and scripts provided in the installation directory. If not, then you’ve been missing out on some valuable functionality.

Command Line Operation

An alternative to the main GUI based application is passing the necessary details to the executable from the command line.
The default installation path of the executable is: C:\Program Files (x86)\robware\rvtools\RVTools.exe

The switches that can be provided are:

  • -s – the ESXi host or vCenter to connect too (upn or ipaddress).
  • -passthroughAuth – use passthrough authentication to connect to the ESXi Host or vCenter (uses current windows logon credentials).
  • -u – username to connect to the ESXi host or vCenter.
  • -p – password to connect to the ESXi host or vCenter.
  • -c – the export option you wish to use.
  • -d – the directory you want to export too.
  • -f – the filename of the exported xlsx or csv. If you don’t pass the filename RVTools will create a filename with a datetimestamp.
  • -ExcludeCustomAnnotations – custom annotation fields are not exported.
  • -ExcludeTags – tag fields are not exported.
  • -DBColumnNames – Uses RVTools intenal column names. Useful if uploading export to a DBMS.
  • -GetFriendlyNames – If using a vSAN and want export to show friendly vSAN name and not UUIDs.
  • -GetFileInfo – Will populate the vFileInfo tab page. Warning: This can take a very long time!

The -c export option switch can be used to tailor exactly what and in which format you want the information exported.

  • -c ExportAll2xlsx – Exports all tabs to xlsx format.
  • -c ExportAll2csv – Exports all tabs to csv format.
  • -c Export<tab>2xlsx – Exports a specific <tab> to xlsx format.
  • -c Export<tab>2csv – Exports a specific <tab> to csv format.

The options for <tab> in the above examples are:
vInfo, vCPU, vMemory, vDisk, vPartition, vNetwork, vUSB, vCD, vSnapshot, vTools, vSource, vRP, vCluster, vHost, vHBA, vNIC, vSwitch, vPort, dvSwitch, dvPort, vSC+VMK, vDatastore, vMultiPath, vLicense, vFileInfo, vHealth

# Start RVTools with userid password, and export all to csv
RVTools -s 192.168.2.220 –u Administrator –p password -c ExportAll2csv -d c:\temp

# Start RVTools with passthrough authentication, and export all to xlsx
RVTools –passthroughAuth –s virtualcenter.domain.local -c ExportAll2xlsx -d c:\temp –f mytest.xlsx

# Start RVTools with userid password, and export vInfo tab to xlsx excluding tags
rvtools -u Administrator -p password -s 192.168.2.220 -c ExportvInfo2xlsx -d C:\Temp -f vInfo.xlsx -ExcludeTags

# Start RVTools with passthrough authentication, and export vHost tab to csv
rvtools -passthroughAuth -s virtualcenter.domain.local -c ExportvHost2csv -d C:\Temp -f vHost.csv

Using RVTools with these command line switches you could setup a scheduled task to regularly export the information to a network share.

I use a daily scheduled task that merges together exports from several vCenters and uploads that file to sharepoint (see Multiple vCenters and Merging Excel Files below).

Email the RVTools Export

An alternative solution to uploading to a share is to email the export as an attachment. A template script (RVToolBatch.cmd) to do this is also provided in the installation directory.

rem #########################
rem Name	RVToolsBatch
rem By		RobWare
rem Date	December 2017
rem Version	3.10.1
rem #########################

rem =====================================
rem Include robware/rvtools in searchpath
rem =====================================
set path=%path%;c:\program files (x86)\robware\rvtools


rem =========================
rem Set environment variables
rem =========================
set $VCServer=<your vc server>
set $SMTPserver=<your smtp server>
set $SMTPport=<your smtp port, default = 25>
set $Mailto=<mail address>
set $Mailfrom=<mail sender address>
set $Mailsubject=<subject, example "RVTools batch report">
set $AttachmentDir=<directory name, example c:\temp>
set $AttachmentFile=<file name, example RVTools.xlsx>


rem ===================
rem Start RVTools batch 
rem ===================
rvtools.exe -passthroughAuth -s %$VCServer% -c ExportAll2xlsx -d %$AttachmentDir% -f %$AttachmentFile%


rem =========
rem Send mail
rem =========
rvtoolssendmail.exe /smtpserver %$SMTPserver% /smtpport %$SMTPport% /mailto %$Mailto% /mailfrom %$Mailfrom% /mailsubject %$Mailsubject% /attachment %$AttachmentDir%\%$AttachmentFile%

To use the script you need to set the environment variables and the Start RVTools batch command. The script finishes by using a utility called rvtoolssendmail.exe to send the export via email. Setting this up as a scheduled task once, will provide you with regular reports.

Multiple vCenters and Merging Excel Files

The command lines and batch file above are great when you are dealing with one vCenter, but like me you may have several you want to get an export from. You could run multiple commands from above, but then you will have multiple csv or xlsx files to merge or manage.

We have two options here. We can run multiple exports from multiple ESXi hosts or vCenters and merge them using the RVToolsMergeExcelFiles.exe provided in the installation folder.

To demonstrate we may have two vCenters we export the vHealth information from. We wish to merge the xlsx files. This would be done with:

RVToolsMergeExcelFiles.exe -input C:\Temp\vcsa1-vHealth.xlsx;C:\Temp\vcsa2-vHealth.xlsx -output C:\Temp\merged-vHealth.xlsx
Done.

We would now have one xlsx file with health information from both vCenters. Again this is fine if you just want to have the file in a folder, but there is a way to send it via a PowerShell script called RVToolsBatchMultipleVCs.ps1.

Setting this script up is a bit more involved. First of all we need to use a utility called RVToolsPasswordEncryption.exe to generate a secure password that can be used in the script so we are not exposing passwords. Start the utility and enter the password. Click Encrypt and then copy the encrypted password:

Next open RVToolsBatchMultipleVCs.ps1. You can immediately see the section:

 -----------------------------------------------------
# Set parameters for vCenter 1 and start RVTools export
# -----------------------------------------------------
[string] $VCServer = "192.168.2.220"                                                    # my test vCenter server
[string] $User = "vsphere.local\rob"                                                    # or use -passthroughAuth
[string] $EncryptedPassword = "_RVToolsPWD2b0J6haEx3lZxIzF0Tv6rMMm5BSGQHtTP++9jjiMMVs=" # use RVToolsPasswordEncryption.exe to encrypt your password
[string] $XlsxDir1 = "C:\RVTools"
[string] $XlsxFile1 = "vCenter1.xlsx"

Just edit the parameters to match your first vCenter, replacing the variable $EncryptedPassword with the output from RVToolsPasswordEncryption.exe. So for example I would change the above to:

# -----------------------------------------------------
# Set parameters for vCenter 1 and start RVTools export
# -----------------------------------------------------
[string] $VCServer = "vc01.corp.example.com"                                           # my test vCenter server
[string] $User = "corp\lwoodhouse"                                                    # or use -passthroughAuth
[string] $EncryptedPassword = "_RVToolsPWD2b0J6haEx3lZxIzF0Tv6rMMm5BSGQHtTP++9jjiMMVs=" # use RVToolsPasswordEncryption.exe to encrypt your password
[string] $XlsxDir1 = "C:\Temp"
[string] $XlsxFile1 = "vc01.xlsx"

Repeat for the sections for vCenter 2 and 3. Simply copy and paste additional parameter sections for 4 or more vCenters.
Note however to update the variables $XlsxDir and $XlsxFile with additional numbers.

Once you have all your vCenters defined scroll down to the bottom of the script to this section:

# -----------------------------------------------
# Merge xlsx files vCenter1 + vCenter2 + vCenter3
# -----------------------------------------------

Here (if only connecting to three vCenters) edit the variable $OutputFile to the location you wish to save the file into. This then uses the utility RVToolsMergeExcelFiles.exe to merge the exported xlsx files (no Excel installation required on the machine) and save it to the file as defined in $OutputFile.

If you had more than three vCenters exporting information, you would just amend the merge utility line as so:

& .\RVToolsMergeExcelFiles.exe -input "$XlsxDir1\$XlsxFile1;$XlsxDir2\$XlsxFile2;$XlsxDir3\$XlsxFile3;$XlsxDir4\$XlsxFile4;$XlsxDir5\$XlsxFile5" -output $OutputFile -overwrite -verbose

At this point you have a xlsx file with all the details for the multiple vCenters. At the end of the script is some code to email the merged xlsx file. Just edit the variables for your environment. For example:

# Mail output xlsx file

[string] $SMTPserver = "smtprelay.corp.example.com"
[string] $SMTPport = "25"
[string] $Mailto = "[email protected]"
[string] $MailFrom = "[email protected]"
[string] $MailSubject = "`"RVTools export all for vCenters""

then finally uncomment the line:

Start-Process -FilePath ".\RVToolsSendmail.exe" -ArgumentList $Arguments -NoNewWindow -Wait

Once the script is run the merged xlsx file will be emailed to the address provided.

One last customisation of the script could be to change the exported information. By default for each vCenter is uses the command line switch -c ExportAll2xlsx:

$Arguments = "-u $User -p $EncryptedPassword -s $VCServer -c ExportAll2xlsx -d $XlsxDir1 -f $XlsxFile1 -DBColumnNames -ExcludeCustomAnnotations"

Like the previous section if you say just want the vInfo tab exported information, search in the script for each instance of ExportAll2xlsx and replace with ExportvInfo2xlsx.

Summary

As you can see, RVTools has a lot of additional functionality beyond what you see using the GUI.
What I haven’t covered here is how you can use an Excel file as a Template when merging. Have a look in the documentation to get more information on using a template.
Finally, thanks to Rob de Veij for their continuing development of such an awesome utility.

4 thoughts on “How To Automate RVTools With Scripts And Scheduled Tasks

    • Author gravatar

      I like to Automating RVTools with Scripts and Scheduled Tasks

      and I try to run (rvtools -u Administrator -p password -s 192.168.2.220 -c ExportvInfo2xlsx -d C:\Temp -f vInfo.xlsx -ExcludeTags) with user name and password and it shows an error (RVTools : The term ‘RVTools’ is not recognized as the name of a cmdlet)
      can you please share the working script

    • Author gravatar

      Yes mandatory to be in the directory where rvtools.exe is otherwise you’ll get .dll linking problems.

Leave a Reply

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