VMware Cloud Community
AnoopNeelamana
Contributor
Contributor

Export List of VMs with Owner name

Hi

 

I want to export VM list of my Vcenter with Username who created that and Power Off Since date. Someone please help me here.

Labels (2)
0 Kudos
3 Replies
scott28tt
VMware Employee
VMware Employee

With something like PowerCLI?

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
Tibmeister
Expert
Expert

I will look through my scripts.  I know I have something that you are looking for using PowerCLI.

0 Kudos
Tibmeister
Expert
Expert

Here's the function I wrote a couple years back.  The function requires you already be connected to your vCenter.

function Get-VMLastPowerTimes
{
   <#
	.SYNOPSIS
        [PowerCLI] Retrieves the power on/off times of one or more VMs
    .DESCRIPTION
        Retrieves the power on/off times of one or more VMs
    .EXAMPLE
        Get-VMLastPowerTimes -VMs "myVM1"
    .EXAMPLE
        Get-VMLastPowerTimes -VMs "myVM1","myVM2"
    .PARAMETER VMs
        Comma-delimited list of VMs
    #>
   [CmdletBinding()]
   param
   (
      [Parameter(Mandatory = $true,
         Position = 0,
         ValueFromPipeline = $true,
         HelpMessage = "Comma-delimited list of VMs")]
      [String[]]$VMs
   )

   $results = foreach ($VM in $VMs)
   {
      $eventsOn = $VM | Get-VIEvent -MaxSamples 10000 | Where { $_.FullFormattedMessage -like "*powered on*" }
      $eventsOff = $VM | Get-VIEvent -MaxSamples 10000 | Where { $_.FullFormattedMessage -like "*powered off*" }

      New-Object PSObject -Property @{
         Name         = $VM.Name
         PowerState   = $VM.PowerState
         LastPowerOn  = ($eventsOn | Sort -Descending | select -Last 1 | select CreatedTime).CreatedTime
         UserPowerOn  = ($eventsOn | Sort -Descending | select -Last 1 | select UserName).UserName
         LastPowerOff = ($eventsOff | Sort -Descending | select -Last 1 | select CreatedTime).CreatedTime
         UserPowerOff = ($eventsOff | Sort -Descending | select -Last 1 | select UserName).UserName
      }
   }

   return $results
}

 

0 Kudos