I currently have a powershell script that is trying to export all the information from VMware vCenter utilising the RVTools powershell commands.
However I have approximately 10 vcenters and instead of copying these lines out for each vcenter, I know there is a way to do this with "foreach ($vcenter in $vcenters) and then save the output to each directory\file ($vcenter1Dir1 \ $vcenter1File1) but I'm not experienced enough with PS to write this out.
# Start cli of RVTools
Write-Host "Start export for vCenter $vcenter1 -ForegroundColor DarkYellow
$Arguments1 = "-u $User -p $EncryptedPassword -s $vcenter1 -c ExportvLicense2xlsx -d $vcenter1Dir1 -f $vcenter1File1"
Write-Host $Arguments1
$Process = Start-Process -FilePath ".\RVTools.exe" -ArgumentList $Arguments1 -NoNewWindow -Wait -PassThru
if($Process.ExitCode -eq -1)
{
Write-Host "Error: Export failed! RVTools returned exitcode -1, probably a connection error! Script is stopped" -ForegroundColor Red
exit 1
}
So was reaching out to see if someone could help with this, I'd really appreciate it.
Many Thanks
The easiest way to do this assuming your current code works for individual runs (I didn't try it with RVtools as I don't have it) would be to create a simple array, another variable and possibly edit your file structure to make this work.
Hopefully that works, but if all you are after is license info for hosts, you can do that with this powercli command as well...