10 Replies Latest reply on Sep 22, 2020 9:46 AM by LucD

    Collect All tasks dfrom vCenter for specific period

    SCharchouf Enthusiast

      Hi All

       

      is there a way to collect all tasks from vcenters?

       

      the idea is to collects tasks and identify VMs that have issues

        • 1. Re: Collect All tasks dfrom vCenter for specific period
          LucD Guru
          Community WarriorsvExpertUser Moderators

          You could start with this.
          But it will return all tasks. So you will have to filter further to get only the tasks that are for VMs.

           

          $start = (Get-Date).AddHours(-8)

          Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

          Where-Object{$_ -is [VMware.Vim.TaskEvent]}

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Collect All tasks dfrom vCenter for specific period
            SCharchouf Enthusiast

            Thanks LucD

             

            I got the idea and just need your help as I need to collect all tasks from multiple vcenters so I create the first part but not sure how I can do for the rest

             

            - Collect tasks from $vCenterIP [All parametre are needed]

            - Create Excel File with worksheet based on vCenter name

             

            ---------------------------------------- Script --------------------------------------------

             

            # LIST OF vCenter

               

                $vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"

             

            # Connection to vCenter

                foreach ($IPAddress in $vCenterIP){

                    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

            }

             

            #Connect to vcenter

            $user = Read-Host "User"

            $password = Read-Host "Password"

             

            Write-Host -f green "Connecting to vCenter Server..."

            Connect-VIServer -Server $vcenter -User $user -Password $password

             

            $start = (Get-Date).AddDays(-5)

             

            Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |

            Where-Object{$_ -is [VMware.Vim.TaskEvent]}

            • 3. Re: Collect All tasks dfrom vCenter for specific period
              LucD Guru
              Community WarriorsvExpertUser Moderators

              You can use the Server parameter and loop through all connected vCenters.

              Something like this

               

              # LIST OF vCenter

              $vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"


              #Connect to vcenter

              $user = Read-Host "User"

              $password = Read-Host "Password"


              # Connection to vCenters

              foreach ($IPAddress in $vCenterIP){

                  Write-Host -f green "Connecting to vCenter Server..."

                  Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

              }


              $start = (Get-Date).AddDays(-5)


              $global:defaultVIServers | %{

                  Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $_ |

                  Where-Object{$_ -is [VMware.Vim.TaskEvent]}

              }

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Collect All tasks dfrom vCenter for specific period
                SCharchouf Enthusiast

                to export all output in one excel file with worksheet can I use something like this

                 

                $fileName = ".\ALL_vCenter_Tasks_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"

                $reportvCenter01 = @()

                $reportvCenter02= @()

                $reportvCenter03= @()

                 

                 

                $reportvCenter01 | Export-Excel -Path $fileName -WorksheetName 'vCenter01'

                $reportvCenter02 | Export-Excel -Path $fileName -WorksheetName 'vCenter02'

                $reportvCenter03 | Export-Excel -Path $fileName -WorksheetName 'vCenter03'

                • 5. Re: Collect All tasks dfrom vCenter for specific period
                  LucD Guru
                  User ModeratorsCommunity WarriorsvExpert

                  You could do like this

                   

                  # LIST OF vCenter

                  $vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"


                  $fileName = ".\ALL_vCenter_Tasks_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"


                  # Connection to vCenter

                  #Connect to vcenter

                  $user = Read-Host "User"

                  $password = Read-Host "Password"


                  foreach ($IPAddress in $vCenterIP){

                      Write-Host -f green "Connecting to vCenter Server..."

                      Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

                  }


                  $start = (Get-Date).AddDays(-5)


                  foreach($vc in $global:defaultVIServers){

                      Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $vc |

                      Where-Object{$_ -is [VMware.Vim.TaskEvent]} |

                      Export-Excel -Path $fileName -WorksheetName $vc.Name

                  }

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Collect All tasks dfrom vCenter for specific period
                    SCharchouf Enthusiast

                    the output is empty and only I can see task on PowerCLI window

                    • 7. Re: Collect All tasks dfrom vCenter for specific period
                      LucD Guru
                      User ModeratorsCommunity WarriorsvExpert

                      Did you add the pipeline symbol (|) at the end of the Where-Object line?

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Collect All tasks dfrom vCenter for specific period
                        SCharchouf Enthusiast

                        thank you I missied it it's working fine now, but for some column I see this entry (VMware.Vim.DatacenterEventArgument) is that normal?

                        • 9. Re: Collect All tasks dfrom vCenter for specific period
                          LucD Guru
                          vExpertCommunity WarriorsUser Moderators

                          When a property in the event is an object on itself (in this case a DatacenterEventARgument), the Export-Excel cmdlet will display the object type and not the content.

                          In fact most properties in a TaskEvent are objects themselves.

                           

                          You would probably get more information on the Task when you write the $event.Info property to the Excel file.

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: Collect All tasks dfrom vCenter for specific period
                            LucD Guru
                            User ModeratorsCommunity WarriorsvExpert

                            Something like this for example

                             

                            foreach($vc in $global:defaultVIServers){

                                Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $vc |

                                Where-Object{$_ -is [VMware.Vim.TaskEvent]} |

                                Select -ExpandProperty Info |

                                Export-Excel -Path $fileName -WorksheetName $vc.Name

                            }

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz