1 2 3 Previous Next 37 Replies Latest reply on Apr 18, 2020 11:40 AM by Narayanan_5245 Go to original post
      • 15. Re: Invoke multiple vcenters from rvtoolsbatch
        vmk2014 Expert

        LucD,

         

        I have 35 vCenter and  need to extract the Rv tools report on a daily basis. I just tried with 2 vc but it throws an error

         

        PS D:\Bob> .\rvtools_report.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:\Bob\rvtools_report.ps1:27 char:102

        + ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att

        +                                                                      ~~~~

            + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException

            + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

         

         

         

        Thanks

        V

        • 16. Re: Invoke multiple vcenters from rvtoolsbatch
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          It looks as if the $att variable is $null, meaning to export files were not created.

          The snippet in this thread is using the parameter -passthroughAuth, meaning that the user currently running the command is allowed to connect to the vCenter(s).

           

          If that is not the case, you can use the -u and -p parameters (see RVTools doc).

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 17. Re: Invoke multiple vcenters from rvtoolsbatch
            Narayanan_5245 Novice

            Thanks Lucd for the script. its working using -u username and -p password for latest vCenter server version.

             

            Could you please help to suggest how we can append the date also along with exported file. Moreover can we able to schedule this trigger automatically via schedule task.

             

            i have tried to schedule the task by calling powershell via batch file but its works only if i run manually, not auto trigger is working.

             

            Kindly advise with your comments.

             

            Regards

            Narayanan.

            • 18. Re: Invoke multiple vcenters from rvtoolsbatch
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              The filename for the report is passed via the -f parameter.

              Change it to something like

               

              -f "RVTools-$($_)-$(Get-Date -f 'yyyyMMdd').xlsx"

               

              To run it via the Task Scheduler you follow the normal method to schedule a PS script.
              For example, have a look at Re: How to schedule the powercli script in task scheduler

              If you can't get it to work, share the code you are using to create the Scheduled Task.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 19. Re: Invoke multiple vcenters from rvtoolsbatch
                Narayanan_5245 Novice

                Thank you LucD quick response. Works Perfect.

                 

                For schedule task, I have copied the arguments -NonInteractive -NoLogo -NoProfile -ExecutionPolicy Bypass from your reference link and updated the task.

                 

                Can you help to suggest if different passwords can be added for each vCenter servers (vCenter1 & vCenter2) in the same script? Kindly advise with your inputs

                 

                $ExportPath = 'C:\Temp\Rvtools'

                 

                 

                $Servers = 'vCenter1,vCenter2'

                 

                 

                $Servers | %{

                 

                 

                . "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" –u Root1 –p _RVToolsPWDRHyqpGAHn3n0d3xGrJzoQrIsq423hxzs= -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'yyyyMMdd').xlsx"

                 

                 

                }

                 

                 

                $smtpServer = 'smtp.testdev.com'

                 

                 

                $to = ''

                 

                 

                $from = ''

                 

                 

                start-sleep -s 100

                 

                 

                $att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName

                 

                 

                 

                Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                 

                • 20. Re: Invoke multiple vcenters from rvtoolsbatch
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  Have a look at the New-VICredentialSToreItem and Get-VICredentialStoreItem.
                  It allows you to add credentials per host.

                  Retrieve the credentials with the hostname, in this case the vCenter name.

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 21. Re: Invoke multiple vcenters from rvtoolsbatch
                    Narayanan_5245 Novice

                    Thank you LucD for the reply and comments. Could you please help to give some reference how this PowerCli cmdlet (New-VICredentialStoreItem) can be incorporated with the existing script?

                     

                    i have tried below like additional line for the 2nd vCenter server

                     

                    $ExportPath = 'C:\Temp\testing'

                    $Servers = 'vCenter1'

                    $Servers1 = 'vCenter2'

                     

                    $Servers | %{

                    . "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u root1 -p _RVToolsPWDRHyqpGC78/X+vSBdoAHn3n0d3xGrJzoQrIsq423hxzs= -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"

                     

                    }

                     

                    $Servers1 | %{

                     

                    . "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u temp1 -p _RVToolsPWD37jLee6Zi+WKbwTIuj9alLMVi0cBORQj0/8XlanLPv2Q9zqbiaHYIPC17E7m+e8I -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"

                     

                    }

                     

                    $smtpServer = 'smtp.globedev.com'

                     

                    $to = ''

                     

                    $from = ''

                     

                    Start-Sleep -s 60

                     

                    $att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName

                    Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                    • 22. Re: Invoke multiple vcenters from rvtoolsbatch
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      You need to set it up first (see comment)

                       

                      # You have to set up the VICredentialstoreItems first (outside this script)

                      #

                      #   New-VicredentialStoreItem -Host vCenter1 -User root1 -Password _RVToolsPWDRHyqpGC78/X+vSBdoAHn3n0d3xGrJzoQrIsq423hxzs=

                      #   New-VicredentialStoreItem -Host vCenter2 -User temp1 -Password _RVToolsPWD37jLee6Zi+WKbwTIuj9alLMVi0cBORQj0/8XlanLPv2Q9zqbiaHYIPC17E7m+e8I

                      #

                       

                      $ExportPath = 'C:\Temp\testing'

                      $Servers = 'vCenter1','vCenter2'


                      $Servers | %{

                          $cred = Get-VICredentialStoreItem -Host $_

                          . "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u $($cred.User) -p $($cred.Password) -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"

                      }


                      $smtpServer = 'smtp.globedev.com'

                      $to = ''

                      $from = ''

                      Start-Sleep -s 60

                      $att = Get-ChildItem -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName

                      Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 23. Re: Invoke multiple vcenters from rvtoolsbatch
                        Narayanan_5245 Novice

                        Thanks LucD for the reply.

                        Do I need to run this as command on PowerCli seperately to set up the VICredentialstoreItems for the vCenters. Then we need to schedule the task to run the script to get the report?

                        Moreover after specifying the date in the script, it sending all the RVtools attachments instead of that date report only.

                        Kindly help to advise with your comments.

                         

                        Regards

                        Narayanan.

                        • 24. Re: Invoke multiple vcenters from rvtoolsbatch
                          LucD Guru
                          vExpertCommunity WarriorsUser Moderators

                          Yes, you will need to set up the VICredentialSToreItems separately, before running the RVTools script.

                           

                          To get only the files with the specific reports, try like this

                           

                          $ExportPath = 'C:\Temp\testing'

                          $Servers = 'vCenter1','vCenter2'


                          $files = @()

                          $Servers | %{

                              $cred = Get-VICredentialStoreItem -Host $_

                              $reportName = "RVTools-$($_)-$(Get-Date -f 'ddMMMyyyy').xlsx"

                              $files += $reportName

                              . "C:\Program Files (x86)\Robware\RVTools\RVTools.exe" -u $($cred.User) -p $($cred.Password) -s "$($_)" -c ExportAll2xls -d "$($ExportPath)" -f $reportName

                          }


                          $smtpServer = 'smtp.globedev.com'

                          $to = ''

                          $from = ''

                          Start-Sleep -s 60

                          $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*.xlsx | select -ExpandProperty FullName

                          Send-MailMessage -SmtpServer $smtpServer -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 25. Re: Invoke multiple vcenters from rvtoolsbatch
                            Narayanan_5245 Novice

                            Hi LucD

                             

                            i am getting the below error after i have tried for one vCenter server via PowerCLI console & powershell as well.

                             

                            Please advise

                             

                            PowerCLI C:\temp\testing> .\rvtools_cred.ps1

                            Get-ChildItem : A positional parameter cannot be found that accepts argument

                            'System.Object[]'.

                            At C:\temp\testing\rvtools_cred.ps1:28 char:8

                            + $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...

                            +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterB

                               indingException

                                + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell

                               .Commands.GetChildItemCommand

                             

                             

                            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 C:\temp\testing\rvtools_cred.ps1:30 char:102

                            + ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                            +                                                                      ~~~~

                                + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBi

                               ndingValidationException

                                + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power

                               Shell.Commands.SendMailMessage

                             

                            Note: Tried the same via powershell console, getting below error. May be i need to import the latest vmware modules into the powershell.

                             

                            Get-VICredentialStoreItem : The term 'Get-VICredentialStoreItem' is not recognized as the name of a cmdlet, function,

                            script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is

                            correct and try again.

                            At C:\Temp\testing\rvtools_cred.ps1:9 char:13

                            +     $cred = Get-VICredentialStoreItem -Host $_

                            +             ~~~~~~~~~~~~~~~~~~~~~~~~~

                                + CategoryInfo          : ObjectNotFound: (Get-VICredentialStoreItem:String) [], CommandNotFoundException

                                + FullyQualifiedErrorId : CommandNotFoundException

                             

                            Get-ChildItem : A positional parameter cannot be found that accepts argument 'System.Object[]'.

                            At C:\Temp\testing\rvtools_cred.ps1:28 char:8

                            + $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...

                            +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException

                                + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

                             

                             

                            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 C:\Temp\testing\rvtools_cred.ps1:30 char:102

                            + ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                            +                                                                      ~~~~

                                + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException

                                + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

                             

                             

                            PS C:\Temp\testing>

                             

                            Regards

                            Narayanan.

                            • 26. Re: Invoke multiple vcenters from rvtoolsbatch
                              LucD Guru
                              User ModeratorsvExpertCommunity Warriors

                              The Get-VICredentialStoreItem cmdlet is in the VMware.VimAutomation.Core module.

                              If your PowerCLI modules are in a folder that is listed in $env:PSModulePath and your PS version is 4 or 5, there should be no need to explicitly import a module.

                              But you can add an Import-Module just to make sure.


                              Also note that in PS 6 or 7 the Get-VICredentialStoreItem is not supported.

                              Are you running the script in PS v6 or v7?

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 27. Re: Invoke multiple vcenters from rvtoolsbatch
                                Narayanan_5245 Novice

                                Hi LucD

                                 

                                PowerCli version below for your reference

                                 

                                PowerCLI C:\temp\testing> Get-PowerCLIVersion

                                 

                                 

                                PowerCLI Version

                                ----------------

                                   VMware vSphere PowerCLI 5.8 Release 1 build 2057893

                                 

                                Can you please suggest for the below error which earlier mentioned for attaching the specific date file to the email from the export path directory.

                                 

                                Get-ChildItem : A positional parameter cannot be found that accepts argument 'System.Object[]'.

                                At C:\Temp\testing\rvtools_cred.ps1:28 char:8

                                + $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...

                                +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException

                                    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

                                 

                                 

                                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 C:\Temp\testing\rvtools_cred.ps1:30 char:102

                                + ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                                +                                                                      ~~~~

                                    + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException

                                    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

                                 

                                Regards

                                Narayanan.

                                • 28. Re: Invoke multiple vcenters from rvtoolsbatch
                                  LucD Guru
                                  Community WarriorsUser ModeratorsvExpert

                                  That is a really old PowerCLI version, I strongly suggest to upgrade (unless you have a valid reason to stay with this old version).

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 29. Re: Invoke multiple vcenters from rvtoolsbatch
                                    Narayanan_5245 Novice

                                    Hi LucD

                                     

                                    Upgraded powercli to 6.5 version (4624819) but still getting the below error. i can see the report generated but getting error in the attachment during the email send.

                                     

                                    Can you suggest.

                                     

                                    PowerCLI C:\temp\testing> .\rvtools_cred.ps1

                                    Get-ChildItem : A positional parameter cannot be found that accepts argument

                                    'System.Object[]'.

                                    At C:\temp\testing\rvtools_cred.ps1:28 char:8

                                    + $att = Get-ChildItem -Name $files -Path $ExportPath -Filter RVTools*. ...

                                    +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                        + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterB

                                       indingException

                                        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell

                                       .Commands.GetChildItemCommand

                                     

                                     

                                    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 C:\temp\testing\rvtools_cred.ps1:30 char:102

                                    + ... rver -Subject 'RVTools reports' -To $to -From $from -Attachments $att

                                    +                                                                      ~~~~

                                        + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBi

                                       ndingValidationException

                                        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power

                                       Shell.Commands.SendMailMessage

                                     

                                     

                                    PowerCLI C:\temp\testing> Get-PowerCLIVersion

                                     

                                     

                                    PowerCLI Version

                                    ----------------

                                       VMware PowerCLI 6.5 Release 1 build 4624819

                                     

                                    Regards

                                    Narayanan.