Automation

 View Only
  • 1.  Script to report on new and deleted VMs in vCenter

    Posted Feb 22, 2022 02:28 PM

    I am trying to get a script together to show created and deleted VMs in the past 30 days in our vCenter. Having a look and it seems that a script through the eventlogs is the way forwards. We do have vROps is proving hard to work....

    So far I have the below for looking at the deleted VMs. This does run but I am having problems getting it to return the ExpandedProperty and show the EntityName (vm name).


    Get-VIEvent -MaxSamples 10000 -Types Info | where {$_.GetType().Name -eq "TaskEvent" -and $_.FullFormattedMessage -eq "Task: VirtualMachine.destroy" } |Select info, CreatedTime, UserName,FullformattedMessage,EntityName

    Info : VMware.Vim.TaskInfo
    CreatedTime : 22/02/2022 12:17:31
    UserName : ****
    FullFormattedMessage : Task: VirtualMachine.destroy
    EntityName

    Or has anyone got something similar or a report i can import to vROps? We want to be able to see the number of new and deleted VMs. So if we build 5 machines and delete 5 machines it shows that, the report it currently would show is no change....



  • 2.  RE: Script to report on new and deleted VMs in vCenter

    Posted Feb 22, 2022 02:42 PM

    Why not look for the VmRemovedEvent instead of the TaskEvent.

    Get-VIEvent -maxsamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) |
    where{$_ -is [VMware.Vim.VmRemovedEvent] }