Hi All,
i was using the Rvtools cmd script to get vCenter Rvtools report of one vCenter. Now i have requirement to get the vCenter RVtools report for multiple vCenters in single attached email , is there any one using such script. please help
See Solved: Re: Invoke multiple vcenters from rvtoolsbatch - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for the quick response as always.
i was running it as PS1 getting below error any thing am missing.
PS D:\RVtoolsScript> .\RvtoolsScript.ps1
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At D:\RVtoolsScript\RvtoolsScript.ps1:19 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
Script
$ExportPath = 'D:\RVtoolsScript'
$Servers = '10.10.10.11','10.10.10.12'
$Servers | %{
. "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -passthroughAuth -s "$($_)" -c ExportAll2xls -d
"$($ExportPath)" -f "RVTools-$($_)"
}
$smtpServer = 'smtpapp.abc.com'
$to = 'myemail@email.com'
$from = 'VxRailRvtools@email.com'
$att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
Are there any files in that export folder at all?
According to the error message it seems no files were produced.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No Excel files generated in Export folder. the same path mentioned in script.ps1 file.
Looks like the recent versions of RVTools have a problem with that code.
In the logs I see
DEBUG RVTools.FMain ExportAllorOne2XLSStartedFromCommandLine Handled Exception: Object reference not set to an instance of an object.
Instead of debugging that error, I updated my code based on the RVToolsBatchMultipleVCs.ps1 script that is included in the RVTools package.
That seems to work for me.
$ExportPath = 'C:\Temp'
$Servers = 'vcenter1','vcenter2'
$Servers | ForEach-Object {
Write-Host "vCenter : $($_)"
$sProcess = @{
FilePath = "C:\Program Files (x86)\Robware\RVTools\RVTools.exe"
ArgumentList = "-passthroughAuth -s $($_) -c ExportAll2xls -d $($ExportPath) -f RVTools-$($_) -DBColumnNames -ExcludeCustomAnnotations"
NoNewWindow = $true
Wait = $true
}
$process = Start-Process @sProcess
if ($Process.ExitCode -eq -1) {
Write-Host "vCenter : $($_)"
Write-Host "Error: Export failed! RVTools returned exitcode -1, probably a connection error! Script is stopped" -ForegroundColor Red
exit 1
}
}
$smtpServer = 'mail.lucd.info'
$to = 'lucd@lucd.info'
$from = 'lucd@lucd.info'
$att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att
You can of course also use the RVToolsBatchMultipleVCs.ps1 script that Rob provides.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Seems same attachment error. its unable to generate the file.
PS D:\RVtoolsScript> .\RvtoolsScript.ps1
vCenter : 10.11.126.32
vCenter : 10.11.126.40
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At D:\RVtoolsScript\RvtoolsScript.ps1:24 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
Then you have to find out why the reports are not generated.
Might be an authentication issue.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Looks like yes, can we add lines which will ask for vCenter authentication and store.
Instead of passthrough, you could try with user/password.
Just change the ArgumentList accordingly
ArgumentList = "–u Administrator –p password -s $($_) -c ExportAll2xls -d $($ExportPath) -f RVTools-$($_) -DBColumnNames -ExcludeCustomAnnotations"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD,
think am almost there. seems something minutee am missing. i added ArgumentList with -U user id and -p password. but its unable to authenticate. i already tried putting user id and password in single inverted comma ' and double inverted comma " , its still unable to authenticate..
any thing am missing here.
ArgumentList = "–u userid@abc.com –p password@123 -s $($_) -c ExportAll2xls -d $($ExportPath) -f RVTools-$($_) -DBColumnNames -ExcludeCustomAnnotations"
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At D:\RVtoolsScript\RvtoolsScript.ps1:24 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
Not that I can see.
Can you connect when you run RVTools interactively?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
with RVtools when i try login its connecting. is the Argumentlist line anything more need to be added are we missing something there.
ArgumentList = "–u Administrator –p password -s $($_) -c ExportAll2xls -d $($ExportPath) -f RVTools-$($_) -DBColumnNames -ExcludeCustomAnnotations"
You could try to encrypt the password, see Solved: Re: RVTOOLS Automation with Secure Authentication - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you please help me with this attached error. how to overcome from this error
Send-MailMessage : Cannot validate argument on parameter 'Attachments'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:24 char:102
+ ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage
That seems to indicate that there are no files fitting the filter in the folder defined in $exportPath
$att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
May i get the example to add the credentials for multiple vcenters