PowerCLI

 View Only
  • 1.  Count of VMs Created and Deleted in One week

    Posted Jun 27, 2012 03:03 PM

    Hi,

    I want to have a powercli script which will give me the count of VMs created and deleted last week in a cluster.

    Please help.



  • 2.  RE: Count of VMs Created and Deleted in One week

    Posted Jun 27, 2012 04:26 PM

    You can use the Get-VIEvent cmdlet and look for the specific events.

    This is an example in it's simplest form.

    $entity = Get-Cluster MyCluster
    $start = (Get-Date).AddDays(-7) $eventTypes = "VmCreatedEvent","VmRemovedEvent"
    Get-VIEvent -Start $start |
    where {$eventTypes -contains $_.GetType().Name} | Group-Object -Property {$_.GetType().Name} | %{   New-Object PSObject -Property @{     Type = $_.Values[0]     Number = $_.Group.Count
      } }


  • 3.  RE: Count of VMs Created and Deleted in One week

    Posted Jun 28, 2012 08:29 AM

    Hi LucD,

    Thanks for your reply.

    There is no output when I as providing -Entity as my Cluster name. But when I am doing $vms = $clustername | Get-vm and mentioning the $vms as entity then the script is showing output. Is there any reason for that. Also when I am mentioning $vms as entity it is taking hell lot of time to retrieve the information. Please find the command which I am running below:

    Get-ViEvent -Entity $vms -maxsamples 10000 -Start (Get-Date).AddDays(-7) -Finish (Get-Date) | where {$_.Gettype().Name -eq "vmCreatedEvent"}



  • 4.  RE: Count of VMs Created and Deleted in One week

    Posted Jun 28, 2012 11:17 AM

    Which PowerCLI version are you using ?

    Do a

    Get-PowerCLIVersion

    For me this works with PowerCLI 5.0.1 against a vCenter 5.x with only the Get-Cluster for the entity.

    The Get-VIEvent cmdlet becomes slower depending on the number of objects you pass via the Entity parameter.

    I notice a that it runs twice as long when I do 'Get-Cluster MyCluster | Get-VM'



  • 5.  RE: Count of VMs Created and Deleted in One week

    Posted Jun 28, 2012 12:01 PM

    Hi LucD,

    I am running 5.0.1 version of powercli on Vsphere 4.1.

    Whenever I am giving 'Get-Cluster My Cluster' as entity it is not returning any value. But when I am giving 'Get-Cluster MyCluster | Get-VM' it is showing the VMs created last week but it is taking long time retrive the info.

    So does it mean Get-ViEvent is unable to retrive the information when entity is given as cluster.



  • 6.  RE: Count of VMs Created and Deleted in One week

    Posted Jun 28, 2012 01:05 PM

    This might perhaps be related to the vSPhere version you are using.

    With vSphere 5.x it seems to work for me.