1 2 3 Previous Next 31 Replies Latest reply on Sep 7, 2010 2:03 AM by AlbertWT

    Reporting through Powershell

    ronmanu07 Enthusiast

      Hi All,

       

      I was wondering if anyone had any 'already setup' scripts that can run basic reports on ESX through VI Powershell?

       

       

       

      Thanks to all in advance. I'm not much of a scritping person, and if anyone has anything already going that is helpful would be much appreciated.

       

       

       

      Cheers.

        • 1. Re: Reporting through Powershell
          buckethead Hot Shot

           

          There are many examples in the VI Powershell Toolkit forum.    Chances are pretty high that whatever you want to do is in there.

           

           

          also, check out the contest entries from the 2008 Powershell contest. 

           

           

          http://communities.vmware.com/community/developer/windows_toolkit

           

           

           

           

           

           

           

           

          • 3. Re: Reporting through Powershell
            Texiwill Guru
            vExpertUser Moderators

            Hello,

             

            Moved to the VI Toolkit (for Windows) forum.

             


            Best regards,

            Edward L. Haletky

            VMware Communities User Moderator

            ====

            Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.

            Blue Gears and SearchVMware Pro Blogs: http://www.astroarch.com/wiki/index.php/Blog_Roll

            Top Virtualization Security Links: http://www.astroarch.com/wiki/index.php/Top_Virtualization_Security_Links

            • 4. Re: Reporting through Powershell
              gboskin Hot Shot

               

              You are just in time I have combined a couple of scripts especailly VMware Health Check script and the Guru assitance of LuCD

               

               

              The Script attached gives you a report ..doing the following

               

               

              1) Lists all ESX servers

               

               

              3)List all clusters and calulates VMware capacity for each cluster

               

               

              Provided detallied information about datstores , RDM and all sorts..

               

               

              This is the mother of all reports ...... Many thankd to  Ivo Beerens ivo@ivobeerens.nl who wrote VMwareHealth Check script and of course LuCD VI tollkit GURU

               

               

              • 5. Re: Reporting through Powershell
                alanrenouf Master
                VMware Employees

                There is also my script which reports a fair bit of information straight into word including bar graphs and pie charts at the following location:

                 

                http://communities.vmware.com/docs/DOC-7070

                • 6. Re: Reporting through Powershell
                  ief Enthusiast

                   

                  Hello gboskin, thanks for using the healthscript. The list all cluster with the calculate the capacity and the RDM info is very good addition.

                   

                   

                  blog www.ivobeerens.nl

                   

                   

                  • 7. Re: Reporting through Powershell
                    gboskin Hot Shot

                     

                    Thanks I have added 3 more section and run this every morning .....However this gives me a dialy report..

                     

                     

                    If i want to get a weekly/monthly  report. for the following sections

                     

                     

                    1)  VM information

                     

                     

                    2) Hosts that average over 75% memory usage.

                     

                     

                    3) M's that average over 75% memory usage.

                     

                     

                    I know i need to use a - Start  and - Finish command ..but not sure how to add this

                     

                     

                     

                     

                     

                    Regards

                     

                     

                    • 8. Re: Reporting through Powershell
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      That report looks great.

                       

                      You could add, like you suggested, the -Start and -Finish parameter to the Get-Stat cmdlet.

                      A handy method to get statistics for the previous day could look like this

                      Get-Stat .... -Start  (get-date).Date.adddays(-1) -Finish (get-date).Date.addminutes(-1)
                      

                      More general you could do it like this

                      $DaysBack = <n>        # Number of days to go back
                      $DaysPeriod = <m>      # Number of days in the interval
                      $StatStart = (Get-Date).Date.adddays(- $DaysBack)
                      $StatFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
                      Get-Stat .... -Start $StatStart -Finish $StatFinish
                      

                       

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 9. Re: Reporting through Powershell
                        gboskin Hot Shot

                        Final edited version.. Yes this script really does look good ..once again a big thanks to  Ivo Beerens ivo@ivobeerens.nl  and LUcD

                        • 10. Re: Reporting through Powershell
                          Rashida11 Novice

                           

                          Wow .. Very good work on this scipt . i really love all the new parameters that have been added.

                           

                           

                          The VM Calculation for daily and weekly memory and cpu used i see is in %. is is possible to get actual values for this ?? .If it can it will be awesome!!!

                           

                           

                          • 11. Re: Reporting through Powershell
                            SetClear Enthusiast

                             

                            All,

                             

                             

                             

                             

                             

                            Here's are few alterations to the script.

                             

                             

                            I have added reporting for the ESX Hosts volume usage which will alert if above 75%.

                             

                             

                            (This to me is rather important as I have had a servers log volume run out of space and it more or less took down the Host and all VMs presently hosted.)

                             

                             

                            I have also added the html formatting into the powershell/html document so that when its emailed it will retain the formatting.

                             

                             

                            I have also changed the email so the the body contains the actual report, but left it attached also so that if the email reader is not capable of reading the html body it can be detached and read inside a browser.

                             

                             

                            To be able to use the additional functionality to get Host system information you will have to install putty/plink and modify the file structure to the plink.exe so that it points to your installed location.

                             

                             

                            Other than that no additional changes besdes smtp stuff is required.

                             

                             

                            • 12. Re: Reporting through Powershell
                              bolsen Hot Shot

                               

                              Can you please explain line 105?

                               

                               

                              What is it doing with "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink"?

                               

                               

                              • 13. Re: Reporting through Powershell
                                SetClear Enthusiast

                                 

                                Bolsen,

                                 

                                 

                                 

                                 

                                 

                                $esx_df = & "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink" -pw Asd123 root@$_ df -h

                                 

                                 

                                This line is running is using the plink command which is calling to putty's api to establish the ssh session without opening the GUI.

                                 

                                 

                                Once it established the session to $_ as root ( the password (-pw....).

                                 

                                 

                                the (df -h) is the remote command that is run and the return values are captured as ($esx_df).

                                 

                                 

                                • 14. Re: Reporting through Powershell
                                  Humpadilly Novice

                                   

                                  Hello Everyone,

                                   

                                   

                                  This is a great script! I have been playing around with it and have managed to use the following to get the Average Memory usage and CPU usage (1 day & 1 week) for the hosts....

                                   

                                   

                                  ######################################################

                                  #Host CPU & Memory Usage

                                  Write-Host "Gathering Host CPU & Memory Usage Information."

                                  function VM-statavg ($vmImpl, $StatStart, $StatFinish, $statId) {

                                  • $stats = $vmImpl | get-stat -Stat $statId -intervalmin 120 -Maxsamples 360 `*

                                  •           -Start $StatStart -Finish $StatFinish*

                                  • $statAvg = "{0,9:#.00}" -f ($stats | Measure-Object value -average).average*

                                  • $statAvg*

                                  }

                                    1. Report for previous day*

                                  $DaysBack = 1  # Number of days to go back

                                  $DaysPeriod = 1 # Number of days in the interval

                                  $DayStart = (Get-Date).Date.adddays(- $DaysBack)

                                  $DayFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)

                                    1. Report for previous week*

                                  $DaysBack = 7 # Number of days to go back

                                  $DaysPeriod = 7 # Number of days in the interval

                                  $WeekStart = (Get-Date).Date.adddays(- $DaysBack)

                                  $WeekFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)

                                  $report = @()

                                  get-vmhost | Sort Name | % {

                                  • $vm = Get-View $_.ID*

                                  •    $vms = "" | Select-Object VMName, DayAvgCpuUsage, WeekAvgCpuUsage, DayAvgMemUsage, WeekAvgMemUsage*

                                  •    $vms.VMName = $vm.Name*

                                  •    $vms.DayAvgCpuUsage = VM-statavg $_ $DayStart $DayFinish "cpu.usage.average"*

                                  •    $vms.WeekAvgCpuUsage = VM-statavg $_ $WeekStart $WeekFinish "cpu.usage.average"*

                                  •    $vms.DayAvgMemUsage = VM-statavg $_ $DayStart $DayFinish "mem.usage.average"*

                                  •    $vms.WeekAvgMemUsage = VM-statavg $_ $WeekStart $WeekFinish "mem.usage.average"*

                                  •    $Report += $vms*

                                  }

                                  $Report | ConvertTo-Html -title "Host CPU & Memory Usage Information" -body "&lt;H2&gt;Host CPU & Memory Usage Information.&lt;/H2&gt;" -head $a | Out-File -Append $filelocation

                                  Write-Host "Host CPU & Memory Usage Information Complete.

                                   

                                   

                                  Does anyone know if there is an easy way to put this into the clusters section report?

                                   

                                   

                                  Also is there a command that lists the datastores per cluster?

                                   

                                   

                                   

                                   

                                   

                                  Cheers

                                   

                                   

                                  Humpa

                                   

                                   

                                  1 2 3 Previous Next