1 2 Previous Next 17 Replies Latest reply on Jun 29, 2010 8:59 AM by LarsOliver

    Where was my VMs located in the past?

    LarsOliver Enthusiast

      I need to know on which ESX host the VMs are located in the past.

       

      I found a script who lists the current esx host where the VMs are located:

       

      $vms =  Get-VM | Sort Name

      $vms | Select Name, @{N="VMHost";E={Get-VMHost -VM $_}}

       

      How I can List the VMs history location? I.e. for the last 3 months?

       

      Thanks in advance

      Oliver

        • 1. Re: Where was my VMs located in the past?
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          You will have to investigate the events for that.

          Have a look at  Monitoring DRS VMotion via Powershell. It only lists DRS initiated vMotions but you can easily adapt this for other types of vMotions.

          Is this waht you were looking for ?

           

           

           

           

          ____________

          Blog: LucD notes

          Twitter: lucd22

          • 2. Re: Where was my VMs located in the past?
            LarsOliver Enthusiast

            LucD,

             

            I've got some errors when running the script. What does this line of code do?

             

            http://Reflection.Assembly::LoadWithPartialName("vmware.vim")

             

            Thank in advance

            Oliver

            • 3. Re: Where was my VMs located in the past?
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              Use the attached script from that thread.

              The forum SW has problems with square brackets.

               

              You can in fact leave out that line, it was used to make sure the PowerCLI assemblies were loaded, but that is now done automatically.

               

               

               

               

              ____________

              Blog: LucD notes

              Twitter: lucd22

              • 4. Re: Where was my VMs located in the past?
                LarsOliver Enthusiast

                LucD,

                 

                thank you for your answer. Unfortunately I´ve got additional errors if i run the script on the vSphere architecture:

                 

                Unable to find type [http://VMware.Vim.TaskHistoryCollector........

                 

                Regards

                Oliver

                • 5. Re: Where was my VMs located in the past?
                  LucD Guru
                  User ModeratorsCommunity WarriorsvExpert

                  Strange.

                  From where are you running the script ? From the PowerCLI prompt ? Or something else ?

                  And what version of PowerCLI do you have installed ? Use

                  Get-PowerCLIVersion
                  

                   

                   

                   

                   

                  ____________

                  Blog: LucD notes

                  Twitter: lucd22

                  • 6. Re: Where was my VMs located in the past?
                    LucD Guru
                    User ModeratorsvExpertCommunity Warriors

                    Have a look at Events – Part 8 – vMotion history.

                     

                     

                     

                     

                    ____________

                    Blog: LucD notes

                    Twitter: lucd22

                    • 7. Re: Where was my VMs located in the past?
                      LarsOliver Enthusiast

                      LucD,

                       

                      great! I´ve run your script "Events – Part 8 – vMotion history" and got all the informations I need to know in a csv file. Thank you for supporting me.

                       

                      But as I tryed to run it a second time the operation failed with this error:

                       

                      A parameter cannot be found that matches parameter name 'Property'.

                      At :line:38 char:14

                      +                $events | % <<<<  {

                       

                      I don´t know whats going on.

                       

                      I am using VMware vSphere PowerCLI 4.0 U1 build 208462

                      and the PowerGuiScript Editor 1.8.0.815

                       

                      Regards

                      LarsOliver

                      • 8. Re: Where was my VMs located in the past?
                        LarsOliver Enthusiast

                        LucD,

                         

                        A second Question:

                         

                        $report | Export-Csv "C:\vMotion-history.csv" -NoTypeInformation -UseCulture

                         

                        What does the parameter -UseCulture do?

                         

                        I cannot found a description using:

                         

                        get-help Export-Csv -detailed

                         

                        Thanks and Reggards

                        LarsOliver

                        • 9. Re: Where was my VMs located in the past?
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

                          The -UseCulture parameter is new in PowerShell v2.

                          The help says "Use the list separator for the current culture as the item delimiter. The default is a comma (,).".

                           

                          I would strongly advice you to upgrade to PowerShell v2 (if you haven't done so already).

                           

                           

                           

                           

                          ____________

                          Blog: LucD notes

                          Twitter: lucd22

                          1 person found this helpful
                          • 10. Re: Where was my VMs located in the past?
                            LucD Guru
                            vExpertCommunity WarriorsUser Moderators

                            Do you get that same error when you run the script a 2nd time from the PowerCLI prompt ?

                             

                             

                             

                             

                            ____________

                            Blog: LucD notes

                            Twitter: lucd22

                            • 11. Re: Where was my VMs located in the past?
                              LarsOliver Enthusiast

                              LucD,

                               

                              thanks, now it works   , great script !

                               

                              But I,ve got only the following colums for my 445 VMs:

                               

                              VM     Time1     Host1     DRS1

                               

                              The DRS1 Colum shows only FALSE entrys. It seems that no VM has moved in the last 30 hours. I will check this again with a longer time period at monday.

                               

                              Thanks

                              LarsOliver

                              • 12. Re: Where was my VMs located in the past?
                                LucD Guru
                                vExpertUser ModeratorsCommunity Warriors

                                Or move 1 or 2 guests before you run the script.

                                Make sure that the guests selection (line 11-13) contains these VMs.

                                 

                                 

                                 

                                 

                                ____________

                                Blog: LucD notes

                                Twitter: lucd22

                                1 person found this helpful
                                • 13. Re: Where was my VMs located in the past?
                                  LarsOliver Enthusiast

                                  LucD,

                                   

                                  thanks for your reply.

                                   

                                  Same status as Friday. I moved one VM. The script detects the new esx, but do not show the esx, where the vm came from, in the table.

                                   

                                  I´ve done a little modification to selected the cluster with this command:

                                   

                                  Get-Cluster -name "mycluster" | Get-VM | %{

                                       $vmHash[http://$_.Name|http://$_.Name] = $_.Host

                                  }

                                   

                                  The correct VMs are displayed in the table, but no movements. Independently if I set the $hours variable to 24, 240 or 750 (1 month). The Size of the csv doesn´t change, it is the same (6KB) and also the number of the VMs.

                                   

                                  I wrote the messages into a log file and found the following message three times.

                                   

                                  New-Object : A parameter cannot be found that matches parameter name 'Property'.

                                  At F:\CPM\vm_motion_history.ps1:62 char:51

                                  +

                                   

                                  The line nr. 62 does not match to the line nr. of your original script, because I added some lines ontop of the script for automatic logon. Do you know what this message means. Is -proterty possibly not available in Powershell V1.0 (We use this version on our servers).

                                   

                                  I hope you can help me, because we need the information where the VMs reside in the past for an audit. Because Oracle Licencing depends on how many ESX-hosts the VM runs in total.

                                   

                                  Thanks

                                   

                                  LarsO

                                  • 14. Re: Where was my VMs located in the past?
                                    LucD Guru
                                    Community WarriorsUser ModeratorsvExpert

                                    No, PowerShell v1 doesn't know the hash -Property.

                                    But you can easily adapt this for PowerShell v1.

                                    Replace these lines

                                    ...
                                                     $migrations  += New-Object PSObject -Property @{
                                                     VMname = $task.EntityName
                                                     Source = $event.Host.Name
                                                     Destination = $event.DestHost.Name
                                                     Start = $task.StartTime
                                                     Finish = $task.CompleteTime
                                                     Result = $task.State
                                                     User = $task.Reason.UserName
                                                     DRS = &{if($task.DescriptionId -like "Drm.*")
                                    ...
                                    

                                    by these lines

                                    ..
                                                     $row = "" | Select VMname,Source,Destination,Start,Finish,Result,User,DRS
                                                     $row.VMname = $task.EntityName
                                                     $row.Source = $event.Host.Name
                                                     $row.Destination = $event.DestHost.Name
                                                     $row.Start = $task.StartTime
                                                     $row.Finish = $task.CompleteTime
                                                     $row.Result = $task.State
                                                     $row.User = $task.Reason.UserName
                                                     $row.DRS = &{if($task.DescriptionId -like "Drm.*")
                                                     $migrations += $row
                                    ...
                                    

                                     

                                     

                                     

                                     

                                    ____________

                                    Blog: LucD notes

                                    Twitter: lucd22

                                    1 2 Previous Next