1 2 Previous Next 21 Replies Latest reply on Feb 25, 2019 8:52 AM by Sureshkumar M

    Exporting RVtools report in CSV from Power Cli automation script

    vmk2014 Hot Shot

      Hi all,

      Can we Export the RV tools Report through Power Cli script.

      I could get the details from RV tools per VC , but i want to get details of RVtools report of multiple VCs in sheet

      from Power Cli script.

       

      E.g.

       

      RVTools.exe -passthroughAuth -s VM01.ze.zk.com -c ExportAll2xls -d %EXPORTDESTINATION% -f VM01_%RUNDATETIME%.xls

       

      START /WAIT RVToolsSendMail.bat smtpek.us.zk.com 25 VMwareMEmailNotifications@ZK.com VMSV49_RVTooolsExport@ZK.com %LOG_FILE_ARCHIVE% >> %LOG_FILE_2% 2>&1

       

      Thanks in advance.

       

      vmk2014

        • 1. Re: Exporting RVtools report in CSV from Power Cli automation script
          vmk2014 Hot Shot

          All i want a scheduled task that would launch it regularly, exports the results with the date in the export file-name. The command line parameters are well documented and described in the documentation.

          • 2. Re: Exporting RVtools report in CSV from Power Cli automation script
            LucD Guru
            User ModeratorsCommunity Warriors

            There is a sample script to use RVTools over multiple vCenters in https://github.com/Sneddo/Powershell/blob/master/VMware/RVToolsExport.ps1

             

            To run a PS script as a scheduled task see Calling PowerShell scripts from Task Scheduler

            • 3. Re: Exporting RVtools report in CSV from Power Cli automation script
              vmk2014 Hot Shot

              LucD,

                First of all, i would like to say thanks to you. Could you,please help me to correct the below errors,though i am getting the output but not sure whether its complete report or not.

               

              PowerCLI C:\temp> .\RVTools_Export.ps1

              Get-ChildItem : Cannot find path 'C:\vmserv1' because it does not exist.

              At C:\temp\RVTools_Export.ps1:37 char:13

              +    $Items = Get-ChildItem "$path\$server"

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

                  + CategoryInfo          : ObjectNotFound: (C:\vmserv1:String) [Get-C

                 hildItem], ItemNotFoundException

                  + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCh

                 ildItemCommand

               

               

              thanks

              vm2014

              • 4. Re: Exporting RVtools report in CSV from Power Cli automation script
                LucD Guru
                Community WarriorsUser Moderators

                Can you include the script you are using ?

                • 5. Re: Exporting RVtools report in CSV from Power Cli automation script
                  vmk2014 Hot Shot

                  LucD,

                    Please find the script below which i am running.

                   

                  (

                     $Servers = @("SWRSVC100"),

                     $BasePath = "C:\Scripts\Powershell\RVToolsExport\Archive",

                     $OldFileDays = 30

                  )

                   

                  $Date = (Get-Date -f "yyyyMMdd")

                   

                   

                  foreach ($Server in $Servers)

                  {

                     # Create Directory

                     New-Item -Path "$BasePath\$Server\$Date" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null

                   

                   

                     # Run Export

                     . "C:\Program Files (x86)\RobWare\RVTools\RVTools.exe" -passthroughAuth -s "$Server.us.kz.com" -c ExportAll2csv -d "$BasePath\$Server\$Date"

                   

                   

                     # Cleanup old files

                     $Items = Get-ChildItem "$path\$server"

                     foreach ($item in $items)

                     {

                        $itemDate = ("{0}/{1}/{2}" -f $item.name.Substring(6,2),$item.name.Substring(4,2),$item.name.Substring(0,4))

                       

                        if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days -gt 0)

                        {

                           $item | Remove-Item -Recurse

                        }

                     }

                  }

                   

                   

                  thanks

                  vm2014

                  • 6. Re: Exporting RVtools report in CSV from Power Cli automation script
                    LucD Guru
                    Community WarriorsUser Moderators

                    I think that line should be

                     

                       $Items = Get-ChildItem "$BasePath\$server"

                     

                    • 7. Re: Exporting RVtools report in CSV from Power Cli automation script
                      vmk2014 Hot Shot

                      Thanks LucD. Its fixed the issue, but now its throws different error

                       

                      PowerCLI C:\temp> .\RVTools_Export.ps1

                      Get-Date : Cannot bind parameter 'Date'. Cannot convert value "28/09/2015" to

                      type "System.DateTime". Error: "String was not recognized as a valid DateTime."

                      At C:\temp\RVTools_Export.ps1:42 char:57

                      +       if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days

                      -gt 0 ...

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

                          + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindin

                         gException

                          + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh

                         ell.Commands.GetDateCommand

                       

                       

                      thanks

                      vm2014

                      • 8. Re: Exporting RVtools report in CSV from Power Cli automation script
                        LucD Guru
                        User ModeratorsCommunity Warriors

                        This is most probably related to the locale you have in use on your station.

                        Could be that your station expects in the format MM-dd-yyyy

                        You can check which format is accepted by for example doing

                         

                        Get-Culture | select -ExpandProperty DateTimeFormat

                         

                        • 9. Re: Exporting RVtools report in CSV from Power Cli automation script
                          vmk2014 Hot Shot

                          LucD,

                            Thanks. The timing will be in Central time, but its weird that even after fixing this error, a new error throws every time. But out put is getting generated.

                           

                          PowerCLI C:\temp> .\RVTools_Export.ps1

                          Get-ChildItem : Cannot find path 'C:\VSXXYwrv100' because it does not exist.

                          At C:\temp\RVTools_Export.ps1:37 char:13

                          +    $Items = Get-ChildItem "$path\$server"

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

                              + CategoryInfo          : ObjectNotFound: (C:\usphicwsrv020:String) [Get-C

                             hildItem], ItemNotFoundException

                              + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCh

                             ildItemCommand

                           

                           

                          I changed  to  $Items = Get-ChildItem "$BasePath\$server" (as suggested above)

                           

                          Get-Date : Cannot bind parameter 'Date'. Cannot convert value "15/20/0929" to

                          type "System.DateTime". Error: "String was not recognized as a valid DateTime."

                          At C:\temp\RVTools_Export.ps1:42 char:57

                          +       if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days

                          -gt 0 ...

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

                              + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindin

                             gException

                              + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh

                             ell.Commands.GetDateCommand

                           

                           

                          Get-Date : Cannot bind parameter 'Date'. Cannot convert value "28/09/2015" to

                          type "System.DateTime". Error: "String was not recognized as a valid DateTime."

                          At C:\temp\RVTools_Export.ps1:42 char:57

                          +       if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days

                          -gt 0 ...

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

                              + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindin

                             gException

                              + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh

                             ell.Commands.GetDateCommand

                           

                           

                          thanks

                          vm2014

                          • 10. Re: Exporting RVtools report in CSV from Power Cli automation script
                            vmk2014 Hot Shot

                            Did you got the chance to see why its throwing the below error while running the script, but it generates the output in csv.

                             

                            Thanks in advance !!

                             

                            vm2014

                            • 11. Re: Exporting RVtools report in CSV from Power Cli automation script
                              LucD Guru
                              User ModeratorsCommunity Warriors

                              There is nothing new to say, the $path variable is not initialised, that should be $basepath.

                              The error line doesn't correspond with the line in the error message, perhaps attach the current version of the script you are running.

                               

                              Your locale doesn't accept that specific date format.

                              What does Get-Culture show ?

                              • 12. Re: Exporting RVtools report in CSV from Power Cli automation script
                                vmk2014 Hot Shot

                                LucD,

                                    Please find the output for Get-Culture. Also, i have attached the current version of the script, which i am running.

                                 

                                PowerCLI C:\temp> Get-Culture

                                 

                                 

                                LCID             Name             DisplayName

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

                                1033             en-US            English (United States)

                                 

                                 

                                thanks

                                vm2014

                                • 13. Re: Exporting RVtools report in CSV from Power Cli automation script
                                  fourg Novice

                                  I fixed this issue for myself by editing line 39 to the following.  Note that the only change is "{0}/{1}/{2}" to "{1}/{0}/{2}"

                                   

                                  $itemDate = ("{1}/{0}/{2}" -f $item.name.Substring(6,2),$item.name.Substring(4,2),$item.name.Substring(0,4))

                                   

                                  Hope this helps.

                                  • 14. Re: Exporting RVtools report in CSV from Power Cli automation script
                                    Viewaskew Enthusiast

                                    How does user authentication work when using this method? I ran it and it brought up an error about username and password and also the GUI login box.

                                    1 2 Previous Next