Automation

 View Only
  • 1.  PowerCLI script VM creation date and user info

    Posted Mar 27, 2019 12:51 PM
    Any power CLI script to get VM creation task details with date and user who created that VM.


  • 2.  RE: PowerCLI script VM creation date and user info

    Posted Mar 27, 2019 01:31 PM

    Been a while since I've worked on it, but check vmCreationNotes in the PowerCLI example scripts here: PowerCLI-Example-Scripts/Scripts at master · vmware/PowerCLI-Example-Scripts · GitHub



  • 3.  RE: PowerCLI script VM creation date and user info

    Posted Mar 27, 2019 02:02 PM

    Sure, try like this.

    Note1: this might run a while, since it will fetch quite a few events

    Note2: you can adapt the value in $vmName to pick a specific set of VMs

    Note3: the sample script that was pointed to in the other answer only goes back 1 day

    $vmName = '*'

    $eventTYpes = 'VmCreatedEvent', 'VmClonedEvent', 'VmDeployedEvent', 'VmRegisteredEvent'


    Get-VM -Name $vmName |

       ForEach-Object -Process {

       Get-VIEvent -Entity $_ -MaxSamples ([int]::MaxValue) |

       where { $eventTYpes -contains $_.GetType().Name } |

       Sort-Object -Property CreatedTime -Descending |

      Select -First 1 |

       ForEach-Object -Process {

       New-Object PSObject -Property ([ordered]@{

       VM = $_.VM.Name

       CreatedTime = $_.CreatedTime

       User = $_.UserName

       EventType = $_.GetType().Name

       })

       }

       }



  • 4.  RE: PowerCLI script VM creation date and user info

    Posted Mar 29, 2019 02:27 PM

    We're looking to gather this same information for a set of VMs we get in a report (daily) that changes. I'm hoping that our 'scripting guy' can add your code to the existing script, targeting only the VMs it's reporting on and add the information in additional columns.

    If he cannot get it to work, I'll be creating a thread of my own asking for some assistance. I suspect LucD would come up with what needs to be tweaked in <10 minutes of the thread being created. :smileywink:



  • 5.  RE: PowerCLI script VM creation date and user info

    Posted Mar 29, 2019 06:16 PM

    If your VMs names are for example in a .txt file, one on each line, you could change the 1st line into

    $vmName = Get-Content -Path .\vmnames.txt



  • 6.  RE: PowerCLI script VM creation date and user info

    Posted Apr 01, 2019 06:15 AM

    Thanks for reply. I tried above script but not getting output as my VM is created in 2017

    Please suggest how can I get older vm creation events by script.



  • 7.  RE: PowerCLI script VM creation date and user info

    Posted Apr 01, 2019 06:48 AM

    In vSphere 6.7 the creation date is available, see William's VM Creation Date now available in vSphere 6.7

    For VMs created in other vSphere versions that property is not available I'm afraid.

    You could try looking at the timestamp on a VM's folder, but that is very unreliable since a VM can be moved, renamed...

    If you didn't archive the events, or kept the extracted data somewhere, I'm afraid you're out of luck.



  • 8.  RE: PowerCLI script VM creation date and user info

    Posted Apr 01, 2019 07:06 AM
    Thanks for your support