Statement on the date of a virtual machine has been created

Is it possible to report on the date on which a virtual machine was created?  This info is stored anywhere with the virtual machine?  Otherwise, he'll find newspapers in VMware Server to say how many virtual machines have been created last year?

Thank you

The Get-VIEvent cmdlet gets its information from the database of vCenter. To be more precise in the VPX_EVENT table. You can only return in time with respect to the first record in this table. To retrieve this date, you can use the following code:

$eventMgr = Get-View EventManager
$filter = New-Object VMware.Vim.EventFilterSpec
$eventCollector = Get-View ($eventMgr.CreateCollectorForEvents($filter))
$eventCollector.RewindCollector | Out-Null
$eventCollection = $eventCollector.ReadNextEvents(1)
$eventCollection[0].createdTime
$eventCollector.DestroyCollector()

The downside to the use of the Get-VIEvent cmdlet is that you must specify the number of records to be returned (100 by default) with the - MaxSamples parameter, and all these records are retrieved from the database. If you find events and you don't have a period, you must provide enough samples to include yours, and it can last forever. The event table can grow very large. In my environment, there are 8 million + records in this table.

For the search of the database of events, I prefer to use the SDK instead of the Get-VIEvent cmdlet. That way I can start research until my records are found, and I can use specific filters to retrieve only the records that are of interest. I also pick up only as many records of the database if necessary. You can search the crΘation from a virtual computer by using the code below:

$vm = Get-VM "myVM"

$eventNumber = 100
$eventMgr = Get-View EventManager

$filter = New-Object VMware.Vim.EventFilterSpec
$filter.Entity = New-Object VMware.Vim.EventFilterSpecByEntity
$filter.Entity.Entity = $vm.ExtensionData.MoRef
$filter.EventTypeId = "vim.event.VmCreatedEvent","vim.event.VmClonedEvent","vim.event.VmDeployedEvent"

$eventCollector = Get-View ($eventMgr.CreateCollectorForEvents($filter))
$eventCollector.RewindCollector | Out-Null
$eventCollection = $eventCollector.ReadNextEvents($eventNumber)
$matches=@()
While ($eventCollection) {
  $matches += $eventCollection
  $eventCollection = $eventCollector.ReadNextEvents($eventNumber)
}
$eventCollector.DestroyCollector()
$matches

See you soon,.

Arnim

Tags: VMware

Similar Questions

  • Determine when a virtual machine has been created

    All,

    I need help to determine what VM 2 were created. Help, please. Can someone help me with a script?

    I have attached a simplified version of this script, it is up to 1 year.

  • virtual machine cannot start, because the snapshot of the virtual machine has been deleted by mistake.

    virtual machine cannot start, because the snapshot of the virtual machine has been deleted by mistake.

    When I start this virtual machine, it prompts: unable to find the 0001.vmdk, this disc is my shot, has been deleted by mistake.

    How to restore this virtual machine.

    You need help with a revival of the 000001.vmdk deleted or do you want to repair the virtual machine so that it works without the snapshot?

    The last option, follow these steps:
    remove the virtual machine from the inventory and edit the vmx file so that it uses the basedisk. Then add the virtual machine to inventory.
    If you need data from the snapshot call me through Skype "sanbarrow" - I may be able to help

  • The data of each virtual machine in the list store

    We would like to know where to find Datastore (MON) our VMs and integrate in our weekly report.

    Someone has an idea, how we could do that?

    Any help would be appreciated!

    The data in the report are in the $report variable.

    Now it depends on where and in what format, you want your state.

    If you want a CSV file, you could do

    
    $report = @()
    Get-VM | Get-View | % {
         $row = "" | select Name, Datastore, Path
         $row.Name = $_.Name
         $row.Datastore = (Get-View $_.Datastore[0]).Summary.Name
         $current = Get-View $_.Parent
         $path = $_.Name
         do {
              $parent = $current
              if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
              $current = Get-View $current.Parent
         } while ($current.Parent -ne $null)
         $row.Path = $path
         $report += $row
    }
    $report | Export-Csv "C:\VM-ds-report.csv" -noTypeInformation
    

    If you want to get a report to HTML format, you can replace the last line to

    
    $report | ConvertTo-Html | Set-Content "c:\VM-ds-report.html"
    

    Note that it comes to the ConvertTo-Html cmdlet in its simplest form, you can use the parameters (- title, - head - body) to improve the output.

    There are a number of samples of these two methods in this community to quit smoking.

    For outlook HTML for example have a peek at the Script to the list of Annotations.

    And there are several scripts for reporting have been entered in the script of last year competition.

    Those that you can find in the community Community Sample Code .

    I almost forgot, there are very nice scripts Alan Renouf that creates reports in Word format.

    Recently, he has even published a script to create a Visio drawing from your infrastructure of VI

    Post edited by: LucD

  • How can change the end of thick disk when a virtual machine has been placed on the disk?

    After you have moved the virtual computer to another stage, chose the thin disk bad. Now, the virtual machine cannot start. the error message says that it must be thick for clustering. So, I need to change it back if possible. Then I moved it back and thick chosed. But, after that, I got a same error. So, after you move, the atatuse disk was not be changed. Is it a way not both directions? How can change the staus thin to thick?

    Thank you!

    George

    Hello George,.

    You can also convert virtual disks in eagerzeroedthick from the command line.

    vmkfstools-j VMname.vmdk allows to convert a thin disk in eagerzeroedthick

    vmkfstools k VMname.vmdk that will do it on a thick disk

    It can also work for a thin disk, click with the right button on the vmdk in browser data store, and then click 'inflate '.

    André

  • Cannot start the virtual machine after you create snapshop

    I found a strange behaviour. I have a Windows 2008 guest that I just copied in my new box ESXi. I am trying to create a snapshot before upgrading the guest to 2012 Windows operating system. The virtual machine has currently no snapshots. Whenever I have create a snapshot, he succeeds, but then I can't start the virtual machine saying that it does not find the vmdk file delta even though I see there in the data store. In order to start the virtual machine, I have to delete the inventory and it readd, but then I lose the snapshot. I also have another computer virtual running Windows 8.1 that does exactly the same thing. How can I create snapshots safely without damaging the virtual machine? I also tried to create the snapshot while the virtual machine has been activated but that makes crashing and then it does not start again, so I have to repeat the process to remove the inventory and it time. Frustrating. See the screenshots, I have attached.

    Once these virtual machines have been in Hyper-V in the past and I just convert to VMware format using the StarWind V2V converter.

    Yes, for an ESXi host and target you must either select the ESX f.vmdk as format target (growable option is for VMware Workstation), or you must convert the virtual machine once more instead of simply upload the files to an ESXi host.

    André

  • Determine the "lineage" of a virtual machine. Hence the model was a given VM is the author?

    Wonder how I could resolve the question of which model our VM was created from. In some circles, there are only a handful of models, and each of them is of a particular type of XP, 2K, 2003, etc. is no biggie. With largest deployments with more models and many of a similar (2003 Standard, Windows 2003 Ent) type, it can get more complicated. Or for otherwise this said, reports on which virtual machines were manufactured in what models;

    I don't know where to start here Sorry for not posting any code or attempts.

    Thank you,

    As I know there is no property that shows what model a virtual machine has been deployed.

    But, based on the script that I wrote for Monitoring DRS VMotion via Powershell , you can review the task and the event log and extract the information from there.

    This script does just that

    
    $days = 10
    $tasknumber = 999
    $eventnumber = 100
    $serviceInstance = get-view ServiceInstance
    $taskMgr = Get-View TaskManager
    $eventMgr = Get-View eventManager
    $report = @()
    $filter = New-Object VMware.Vim.TaskFilterSpec
    $filter.Time = New-Object VMware.Vim.TaskFilterSpecByTime
    $filter.Time.beginTime = (Get-Date).AddDays(-$days)
    $filter.Time.timeType = "startedTime"
    $collectionImpl = Get-View ($taskMgr.CreateCollectorForTasks($filter))
    $dummy = $collectionImpl.RewindCollector
    $collection = $collectionImpl.ReadNextTasks($tasknumber)
    while($collection -ne $null){
            $collection | Where-Object {$_.DescriptionId -eq "VirtualMachine.Clone"} | Sort-Object StartTime | % {
                    $efilter = New-Object VMware.Vim.EventFilterSpec
                    $efilter.eventChainId = $_.EventChainId
                    $TemplateDeploy = $false
                    $ecollectionImpl = Get-View ($eventMgr.CreateCollectorForEvents($efilter))
                    $ecollection = $ecollectionImpl.ReadNextEvents($eventnumber)
                    while($ecollection -ne $null){
                            foreach($event in $ecollection){
                                    switch($event.GetType()){
                                            "VMware.Vim.TaskEvent"{
                                                    $startTime = $event.CreatedTime
                                            }
                                            "VMware.Vim.VmDeployedEvent" {
                                                    $status = $event.FullFormattedMessage
                                                    $endTime = $event.CreatedTime
                                                    $templateDeploy = $true
                                            }
                                            "VMware.Vim.VmDeployFailedEvent"{
                                                $status = $event.FullFormattedMessage
                                                    $endTime = $event.CreatedTime
                                                    $templateDeploy = $true
                                            }
                                            "VMware.Vim.VmBeingDeployedEvent"{
                                                $template = (Get-View $event.SrcTemplate.Vm).Name
                                                    $target = $event.SrcTemplate.Name
                                                    $user = $event.UserName
                                            }
                                            Default {}
                                    }
                            }
                            $ecollection = $ecollectionImpl.ReadNextEvents($eventnumber)
                    }
                    if($TemplateDeploy){
                            $row = "" | Select StartTime, EndTime, VMname, Template, User, Status
                            $row.StartTime = $startTime
                            $row.EndTime = $endTime
                            $row.VMname = $target
                            $row.Template = $template
                            $row.user = $user
                            $row.Status = $status
                            $report += $row
                    }
                    $ecollectionImpl.DestroyCollector()
            }
            $collection = $collectionImpl.ReadNextTasks($tasknumber)
    }
    $report | Export-Csv "C:\Clone-Template-Report.csv" -noTypeInformation 
    

    With the variable $days at the beginning of the script, you can set how many days you want to go back.

    Note that it depends of course how long you keep your tasks and events in your database of VC!

    Update : the script will report now also on deployments models failed.

  • Virtual machine has 12 virtual processors, but the host only supports 8?

    Hi all I am using ESX 5.1 and have a machine Windows 2012 R2 Standard of virtual (vmx-09) comments that I'm moving to 8 processors to 12 processors.  But when I turn on the virtual machine after changing the UC 12 I get the error message

    "Virtual Machine has 12 virtual processors, but the host only supports 8. The number of virtual processors can be limited by the selected guest OS for the virtual machine or the granting of licenses for the host".

    Now, I know that 2012 R2 Standard Windows can handle 12 processors and I thought that ESX 5.1 could also, but I'm wrong?  This is the Standard of vSphere license 5.  Thank you!

    Hello

    vSphere 5.1 Standard license has a 8 vCPU per VM limit.

    Company = 32 vCPU

    Business + 64 vCPU

    You must upgrade to vSphere 5.5. This can be done with your vSphere license 5, as it is for all versions 5.X of vSphere and vCPU limit has been deleted in 5.5.

    So you can have as many vCPU per VM that your host has logical cores.

    Tim

  • Virtual machine has 8 virtual processors, but the host only supports 4... ?

    Hello

    My setup is a VSphere cluster with 4 guests each with:

    E5450 3.00 Ghz Dual Xeon Quad & 32 GB of Ram.

    I run a number of virtual machines, mainly Windows 2003 Server Enterprise. Most of them is running on 2 or 4 virtual processors.

    I tried to create a new virtual machine with virtual cpu 6 or 8 and 16 GB of ram. When I tried to turn on the virtual machine, I got the message below:

    Virtual machine has 8 virtual processors, but the host supports only 4. The number of virtual processors can be limited by the OS, etc...

    Now, I checked my licenses and they are for each host that I have:

    Company of VSphere 4. 1-6 cores per processor. 2 cpu by assigned host.

    Thus, it cannot be a problem with the license...

    Any ideas?

    Hello and welcome to the forums.

    The Enterprise Plus edition is required for vSMP 8 channels.  You can check in the vSphere editions comparison.  The Enterprise edition will be limited to 4 vCPUs.

    The 6 cores per processor refers to the ESX host itself and directly relate to the SMP virtual machine.

    Good luck!

  • Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine

    Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine. My questions is the correct statement to the variable: $VmCreated7DaysAgo: $_CreatedOn "-lt" $CDate7.

    # #SCRIPT_START

    $file = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\VM-Repo.csv".

    $Import = import-csv $file

    $VMCreatedLast7RDayRepoFile = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\Last7Days.csv".

    $start7 = (get-Date). AddMonths(-1)

    $CDate7 = $start7. ToString('MM/dd/yyyy')

    $VmCreated7DaysAgo = $Import | Select-object - property name, Powerstate, vCenter, VMHost, Cluster, file, Application, CreatedBy, CreatedOn, NumCpu, MemoryGB | Where-Object {$_.} CreatedOn - lt $CDate7} | Sort-Object CreatedOn

    $TotalVmCreated7DaysAgo = $VmCreated7DaysAgo.count

    $VmCreated7DaysAgo | Export-Csv-path $VMCreatedLast7RDayRepoFile - NoTypeInformation - UseCulture

    Write-Host "$TotalVmCreated7DaysAgo VMs created in 7 days" - BackgroundColor Magenta

    Invoke-Item $VMCreatedLast7RDayRepoFile

    # #SCRIPT_END

    You can use the New-Timespan cmdlet in the Where clause, it returns the time difference between 2 DateTime objects.

    An example of this cmdley

    New-TimeSpan-start (Get-Date). AddDays(-7)-end (Get-Date). Select days - ExpandProperty

    In your case, you could do

    Where {(New Timespan-démarrer ([DateTime] $_.))} CreatedOn) - end $start7). {7 days - gt}

    But beware of negative numbers.

  • Average throughput of the network to a virtual machine with PowerCLI

    I would get average network throughput for a virtual machine with PowerCLI including all e-cards, the virtual machine has for the last week (not including NFS or storage of traffic-related).

    How best should add this report:

    Get - vm myvm | Select name, numcpu

    Thank you!

    Try like this

    Get-VM | Select Name, @{N="Avg Network Throughput MBPs";E={    [math]::Round((Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7) -Stat "net.throughput.usage.average" |    where {$_.Instance -eq ""} |    Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1KB,2)}}
    

    The script takes the aggregate value for all NICs for (the one where the Instance is an empty string).

    Then we take the average and converts the Kbps, Mbps.

  • Get the data from a virtual computer store

    I'm looking to get the data from a virtual computer store, but format to be used with vmrun.  My current vmrun statement is:

    vmrun t CR h < IPAddress > https://: 443/SDK u & lt; username & gt; Pei & lt; password & gt; runProgramInGuest "[& lt;. datastorename & gt;] & lt; datastorefolder & gt; / & lt; virtualmachinename & gt;. VMX' c:\myscript.bat

    The idea is to replace & lt; datastorename & gt; given with the name of the LUN that is running on a virtual machine.  In this case, I'm running my statement vmrun from inside a script PowerCLI.  I can use a variables powerCLI, if the vmrun instruction can take and use all escape sequences are needed to adapt the format vmrun to this argument.

    That is right.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Question about the size of my Virtual Machine

    I'm on Fusion 3.1 (and Windows XP in Fusion on a MacBookPro Leopard). I put my Windows Virtual Machine to be 40 GB size but I just ran OmniDiskSweeper and it shows that the virtual machine takes 53 GB. I see the same size in the Finder.

    Two questions: first, how is it possible for the virtual machine to limit growth, I gave him? Second, is there a way for me to downsize (safely). I did not quite in the virtual machine (mainly my installation of Windows) and a handful of programs so it's weird that she's so big.

    I have disabled Auto-protect.

    I have two snapshots, one of when I first set up the virtual machine and one of very recently. I once had a bunch of other photos but I deleted them. I mention this because I read in another thread that "orphan" instant can hang out somewhere but I don't know where to look to see if this is the reason for the growth of my virtual machine.

    Thanks a lot for your suggestions.

    Abe Z.

    AMZ1 wrote:

    One thing I didn't get your last answer: if snapshots are not backup, and the creation of a snapshot causes the basic disk that you want to stop growing, which are good for snapshots? Or in other words, your response, it looks like I should stop creating snapshots, Yes?

    In which case I should rely only on periodically manually save the virtual machine by copying in the Finder on an external drive?

    What I said was "Snapshots are not backups in the traditional sense of the word and should not be relied upon as such either." However, using clichés absolutely has merit and value but how to use them effectively and efficiently seems to escape most of the users.  As a general rule, I treat a not different Virtual Machine and a physical Machine, then when it come to back up the user data and the ability to quickly restore the entire construction as well as user data.  I use snapshots mainly for short periods of time, and then either delete them when I don't want to lose changes made along the way, or if I go back to a previous snapshot.  For example, I can run on a given snapshot and say a single snapshot for a week and if all was well I'll delete it and take another or if I need to do something that could end up with bad results I'll take a snapshot to do what I do and if I have a problem just go back to the previous snapshot or the basic disk as appropriate.  The trick is user data constantly backed up out of the Virtual Machine itself, as well as at some point in time I never have to worry about the State of and reason for any data or instant and what action I might have to or want to take.

    There are many other cases workers scenarios about how/when to use snapshots and it was just a bit of food for thought because I don't have time now to get deeper into it but the snapshots are a good thing to use as and when necessary, but do not count on them to replace the traditional methods/methodologies for backup/recovery of data user or any backup/restore system but use then as a another tool in the digital Toolbox.

  • Get use of the resources of all virtual machines in a cluster

    Hello

    I have developed a measure of capacity management report that collects all the use of the resources of the virtual machines in a datacenter. The function that collects it looks like this:

    def hostMemoryConsumed =]

    def memoryConsumed = 0.0f

    def memoryGranted = 0.0f

    VMs. each() {}

    VM->

    try {}

    memoryConsumed += vm.host.memory.consumed.current.average / 1024.0f<----- how="" to="" do="" this="" to="" get="" from="">

    memoryGranted += vm.host.memory.capacity.current.average / 1024.0f

    }

    {} catch (NullPointerException e)

    }

    VMS is a function of type parameter VMS VMW

    The works above for virtual machines in the data center, but I need it to be after cluster. I can find a cluster of virtual machines, but I'm having trouble with referring to specific values for example consumed memory and capacity.

    If I change the type parameter: VMW Cluster how the metric reference would look like (see the try {})?

    I don't think that a query will help me.

    Thanks in advance

    Erik Alm

    If you want to do for a cluster, you can just get the list of virtual machines in a cluster of first and passing in your script.  If you have a function for a VMWCluster you can add a parameter for "vmwCluster" that is underneath and it should give you a table (topologyObjects) that has all the virtual machines in the cluster.

    QS = server.get ("QueryService") / / query Service

    tquery = qs.createStatement("!) (' VMWVirtualMachine where esxServer.parent.name = "+" ' "+ vmwCluster +" "" ") .setQueryTopologyObjects (true);

    topologyObjects = qs.executeStatement (tquery) .getTopologyObjects)

  • Can join a Cluster of storage disk out of Maintenance DTS Mode to set up the profiles for a virtual machine storage policies?...

    Can join a Cluster of storage disk out of Maintenance DTS Mode to set up the profiles for a virtual machine storage policies?...


    IE can you define the rules of affinity DTS depending on how the rules of storage of profiles are configured for a virtual machine?

    In my mind it seems there is disconnect from the DTS and storage profiles.

    Thank you.

    = NOTE =.

    My lab at home, 2 organizes running ESXi 5.0

    Dv01 has

    Of startup vmfs 7200 RPM 160 G = dv01-BOOT

    Vmfs 1 TB 7200 RPM = VM02-VMFS

    VM02 has

    Of startup vmfs 7200 RPM 160 G = VM02-BOOT

    Vmfs 1 TB 7200 RPM = VM02-VMFS

    Vmfs 5900 RPM 2 TB = VM02-TV01

    I have (3) facility profiles of storage using 'User-defined storage Capablity' as shown below:

    (160 @ 7200 RPM SATA) boot > Boot

    Fast (160 7200 RPM SATA and 1 TB @ 7200 RPM SATA) > fast

    Slow (2 TB @ 5900 RPM SATA) > slow

    Then, I set up a storage Cluster with my local disks on dv01 (only to date)

    LocalVM disc dv01-BOOT and dv01-VMFS disk of the 'cluster of storage.

    I have a computer virtual called DC01 (HardDisk1) want to live on 'Boot' profile storage drive
    His "Non-compliant" poster according to the storage profile, it should run on drive 'boot' on dv01

    To get to this point, I put the StorageCluster in Mode of Maintenace 'DTS' and forced a sVmotion of all virtual machines off dv01-BOOT

    No disks are IO or claim of space.

    But once I take the 'DTS Maintenacne mode' STARTUP dv01 floppy is now get the DTS to return him to satisfy the storage profile (rule) I install... IE do the 'storage profile' VM complient (without doing a few externall API, the PS script or the 3rd party software calls)... ??

    Seems weird it is (or may be) such disconnection of a memory of the profiles and the StorageClusters and the DTS?

    Thank you...

    At this point, I think that storage DRS and storage profiles are two technologies to separate and work independently, but what you suggest is a great idea-

Maybe you are looking for

  • Clone of Win and Time Capsule

    Hello. I am currently on a MBPro, with El Capitan, Bootcamp and Windows 10.  I have a Time Capsule for wireless backup. Will it partition and format the time Cap. While Win Clone can use it for backups?  Or can I just format the whole TC in a format

  • CAN SOMEONE HELP ME WITH THIS!

    I tried to delete a folder on my trash, but gets no chance I tried a lot of different of that, but I get nothing... that's what he said RM: ~rf/Volumes/ThaBeatCreators. Trashes/501/Big Mike Roll Call: no such file or directory

  • An XP activation code usable after a Windows 7 upgraded?

    Hello I have an older office that I would like to reformat and reinstall Windows XP. However, when I bought Windows 7 for my new desktop PC, I bought the upgrade version and used my XP key.  If I reinstall XP on the old machine, I'll be able to activ

  • bios password HP desktop p6725it

  • My Windows is unable to shutdown or restart System

    I have Windows 7 Ultimate Service Pack 1 on my PC. Sometimes when I restart or shut down my windows, I click on stop or restart several times, BUT it turned off at all! This happens often when I worked with my PC, a lot of time. Can U help me?