1 2 3 Previous Next 33 Replies Latest reply on Sep 20, 2017 7:31 PM by JuanJesusMendoza

    Get VM's creation date

    GuilhermeStela Enthusiast

      It's possible to get the exact creation time of a VM?

      I'm seeing here in the tasks and events but ain't found. Maybe some PowerCli cmdlet exclusive for reports?

        • 1. Re: Get VM's creation date
          tigerdeccan Hot Shot
          function Get-VMCreationTimes {
             $vms = get-vm
             $vmevts = @()
             $vmevt = new-object PSObject
             foreach ($vm in $vms) {
                #Progress bar:
                $foundString = "       Found: "+$vmevt.name+"   "+$vmevt.createdTime+"   "+$vmevt.IPAddress+"   "+$vmevt.createdBy
                $searchString = "Searching: "+$vm.name
                $percentComplete = $vmevts.count / $vms.count * 100
                write-progress -activity $foundString -status $searchString -percentcomplete $percentComplete
          
                $evt = get-vievent $vm | sort createdTime | select -first 1
                $vmevt = new-object PSObject
                $vmevt | add-member -type NoteProperty -Name createdTime -Value $evt.createdTime
                $vmevt | add-member -type NoteProperty -Name name -Value $vm.name
                $vmevt | add-member -type NoteProperty -Name IPAddress -Value $vm.Guest.IPAddress
                $vmevt | add-member -type NoteProperty -Name createdBy -Value $evt.UserName
                #uncomment the following lines to retrieve the datastore(s) that each VM is stored on
                #$datastore = get-datastore -VM $vm
                #$datastore = $vm.HardDisks[0].Filename | sed 's/\[\(.*\)\].*/\1/' #faster than get-datastore
                #$vmevt | add-member -type NoteProperty -Name Datastore -Value $datastore
                $vmevts += $vmevt
                #$vmevt #uncomment this to print out results line by line
             }
             $vmevts | sort createdTime
          }
          1 person found this helpful
          • 2. Re: Get VM's creation date
            GuilhermeStela Enthusiast

            if i want write to a file i could use in wich line?

             

             

            this one?

             

            write-progress -activity $foundString -status $searchString -percentcomplete $percentComplete

            • 3. Re: Get VM's creation date
              GuilhermeStela Enthusiast

              I guess the createdTime is wrong....

               

               

              createdTime         name                IPAddress           createdBy -----------         ----                ---------           --------- 23/2/2012 10:19:18  MyVM                {x.x.x.x}


              This VM was created a long time ago and i'm having the same problem for another VMs.

               

              Maybe i don't have sufficient event logs?

              • 4. Re: Get VM's creation date
                nl26348 Novice

                When I run this script I get no result.

                Anyone idea?

                • 5. Re: Get VM's creation date
                  tigerdeccan Hot Shot

                  check if you have logs in Vcenter database .

                  • 6. Re: Get VM's creation date
                    LucD Guru
                    vExpertUser ModeratorsCommunity Warriors

                    Note that by default the Get-VIEvent cmdlet only returns 100 events.

                    That could explain why you are missing some creation dates.

                    Change this

                    Get-VIEvent $vm

                    into

                    Get-VIEvent $vm -MaxSamples ([int]::MaxValue)
                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 7. Re: Get VM's creation date
                      nl26348 Novice

                      Get-VIEvent $vm -MaxSamples ([int]::MaxValue) gave the same empty black result.

                      I see logs in the vcenter database.  The statistics level is 1. The day interval duration 1 day is deselected.

                      • 8. Re: Get VM's creation date
                        LucD Guru
                        Community WarriorsUser ModeratorsvExpert

                        The retention of tasks and events is controlled by the Database Retention Policy (<Administration><vCenter Server Settings>).

                        If you have retention active for a limited number of days, the events and tasks have been removed.

                         

                        This has nothing to do with the Statistics.

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: Get VM's creation date
                          nl26348 Novice

                          Ok thx! The Database Retention Policy for tasks and events is 30 days.

                          • 10. Re: Get VM's creation date
                            LucD Guru
                            vExpertCommunity WarriorsUser Moderators

                            That means you can't find creation dates for VMs that were created more than 30 days ago.

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: Get VM's creation date
                              nl26348 Novice

                              Yes, but we have several vm's created within 30 days.

                              • 12. Re: Get VM's creation date
                                GuilhermeStela Enthusiast

                                well, now i'm afraid that someone has misconfigured it....

                                 

                                see the atachment pls.  With this checkboxes unmarked what is the pattern?

                                • 13. Re: Get VM's creation date
                                  LucD Guru
                                  Community WarriorsvExpertUser Moderators

                                  Those settings mean that there is no retention period.

                                  All events and tasks are kept in the vCenter database forever.

                                   

                                  It could be that your VMs are created in a special way and that this method does not generate the eventtype the script is looking for.

                                  A way to find out, create a new VM like you normally do.

                                  Then collect all the events for the last hour and the list the eventtypes.

                                  Something like this

                                  Get-VIEvent -Start (Get-Date).AddHours(-1) -MaxSamples ([int]::MaxValue) |

                                  Group-Object -Property {$_.GetType().Name}

                                  Perhaps the list will shed a light why you don't see your VM creation dates.

                                  If you see a lot of TaskEvents, we will have to look at the type of tasks.

                                  Like this

                                  $events = Get-VIEvent -Start (Get-Date).AddHours(-1) -MaxSamples ([int]::MaxValue) |
                                  where {$_.GetType().Name -eq "TaskEvent"} |
                                  Group-Object -Property {$_.Info.DescriptionId}
                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 14. Re: Get VM's creation date
                                    GuilhermeStela Enthusiast

                                    Thanks again Luc, those scripts helped me to find events in some Vms here.

                                     

                                     

                                     

                                    I realize that we migrate three structures to a unique vCenter recently.. so the logs apoint to the migration`s day. =)

                                     

                                    thanks everybody for the help!

                                    1 2 3 Previous Next