PowerShell Code

I like to create a Scheduled Task in vRealize Orchestrator to create RVTools files everyday. Here is a sample script that could be used. The script is also on a 7 day rotation of files and automatically deletes old files.


Start-Process -FilePath "C:\Program Files (x86)\Robware\RVTools\RVtools.exe" -ArgumentList '-s vCenter01.vCrocs.info -u administrator@vsphere.local -p "Enter RVTools encrypted Password between the double quotes" -c Exportall2xls -d "G:\RVTools\vCenter01"' -Wait

Start-Process -FilePath "C:\Program Files (x86)\Robware\RVTools\RVtools.exe" -ArgumentList '-s vCenter02.vCrocs.info -u administrator@vsphere.local -p "Enter RVTools encrypted Password between the double quotes" -c Exportall2xls -d "G:\RVTools\vCenter02"' -Wait

# Delete all RVTools Files that are older than 7 day(s)
$Path = "G:\RVTools"
$Daysback = "-7"
 
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path -Recurse | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item -Confirm:$false -Force -Recurse

Article Updated: 2021-04-24