$VIserver = Read-host "Type the Virtual Center you want to find created date of VMs:" Connect-VIServer $VIserver write-host write-host write-host write-host write-host $Nametouse = Read-host "Type the VM name or wildcards to search for, Ex: ivml2106 or ivml210* or ivml21* or ivml*:" if ($VIServer -eq ""){ Write-host "You have not mentioned VI server name without this info script cannot continue, please try again" -forgroundcolor "Red" } else { if ($Nametouse -eq ""){ Write-Host " You have not mentioned any VM names are wild cards to search for, assuming you need info for all VMs, if that is not the case kindly hit Ctrl+C to abort" -foregroundcolor "Yellow" $VMs = Get-VM }else { $VMs = get-vm -name $Nametouse }} $vm = $vms | Sort Name Write-host Write-host Write-host Write-host "Thank you for providing all inputs that is necessary, I am working on your request please wait ......" -foregroundcolor "Green" @(Foreach ($VM in $VMs){ #$Created = "" $Event = $VM | Get-VIEvent -Types Info | Where { $_.Gettype().Name -eq "VmBeingDeployedEvent" -or $_.Gettype().Name -eq "VmCreatedEvent" -or $_.Gettype().Name -eq "VmRegisteredEvent" -or $_.Gettype().Name -eq "VmClonedEvent" -or $_.Gettype().Name -eq "VmDiscoveredEvent"} $Created = $Event.CreatedTime $User = $Event.UserName Write-Output "$($VM, $Created, $User, $Event)" #Write-host "=========================================" #Write-host $VM #Write-host $Created #Write-host $Event #Write-host "=========================================" }) | Out-file C:\pscripts\output\test.csv -enc ASCII -append disconnect-viserver $VIserver -confirm:$false