VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot

Script to get Multiple vCenters RVtools Report via email in single attachement

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

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Labels (2)
0 Kudos
16 Replies
LucD
Leadership
Leadership

0 Kudos
RajuVCP
Hot Shot
Hot Shot

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

 

 

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
RajuVCP
Hot Shot
Hot Shot

No Excel files generated in Export folder. the same path mentioned in script.ps1 file.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
rGunnal
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
RajuVCP
Hot Shot
Hot Shot

Looks like yes, can we add lines which will ask for vCenter authentication and store.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
RajuVCP
Hot Shot
Hot Shot

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

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
LucD
Leadership
Leadership

Not that I can see.
Can you connect when you run RVTools interactively?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RajuVCP
Hot Shot
Hot Shot

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"

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
ajkumar194
Contributor
Contributor

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

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Here is the script ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $ExportPath = 'C:\Temp' $Servers = 'VBVACSOSMAVC01.vsmainfra.local' $Servers | ForEach-Object { Write-Host "vCenter : $($_)" $sProcess = @{ FilePath = "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" ArgumentList = "–u Administrator –p password -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 = '57.203.253.19' $to = @('om.himanshu@orange.com';'ajay.kumar@orange.com';'frederic.laval@orange.com';'frederic.assemat.ext@orange.com') $from = 'noreply.vcenter_vsma@orange.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
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Mmanjunath
Contributor
Contributor

May i get the example to add the credentials for multiple vcenters

0 Kudos