Miscellaneous script - Who Created that VM ?

Version 2

    Introduction

    A script to add information back into the vSphere client, this script which is designed to run once a day (or more) as a scheduled task, will add a custom attribute to each VM with the creator and date created of that VM.

     

    Once this has been completed the information can clearly be seen by all users of the vSphere client:

     

     

     

     

     

     

     

     

     

    This script will also enable you to populate data for further scripts to use this information and list the following:

     

    • Who created the VMs (See below - Appendix 1)

    • Who created the most VMs (See below - Appendix 2)

    • How many VMs were created each month (See the PowerCLI blog here)

     

    Requirements

    For this script to run correctly:

     

    • The account running this script will need permissions in vCenter

    • The account running this script will need read permissions of Activde Directory (Domain Users have this by default)

    • The machine executing this script will need to be a member of the domain

    • You will need the AD Cmdlets from Quest installed (Download them from here)

     

    Execution

    1. Edit the script and alter the first Connect-VIServer line to use your vCenter connection details (for more information on connection details run get-help connect-viserver -full from the PowerCLI prompt)

    2. Run this script from a PowerCLI prompt  ./WhoCreatedThatVM.ps1

    3. Once it has been confirmed that this script is working you can add it as a scheduled task (click here for more details)

     

    Appendix 1

    Get-VM | Select Name -ExpandProperty CustomFields | Where {$_.key -eq "CreatedBy"} | Out-GridView
    

     

     

     

     

    Appendix 2

    Get-VM | Select Name -ExpandProperty CustomFields | Where {$_.key -eq "CreatedBy"} | Group-Object  | Select Count, Name | Sort Count -Descending |Out-GridView