$VIserver = Read-host "Type the Virtual Center you want to find created date of VMs:" write-host write-host if ($VIServer -ne ""){ Connect-VIServer $VIserver Write-Host Write-Host "Connected to VI Server" Write-Host $Nametouse = Read-host "Type the VM name or wildcards to search for, Ex: ivml2106 or ivml210* or ivml21* or ivml*:" if ($Nametouse -eq ""){ Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 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" Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" $VMs = Get-VM } else { $VMs = get-vm -name $Nametouse } }else { Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" Write-host "You have not mentioned VI server name without this info script cannot continue, please try again" -foregroundcolor "Red" Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" } $vm = $vms | Sort Name @(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 $VMMemory = $VM.MemoryMB $VMCpu = $VM.NumCpu $VMPowerStatus = $VM.PowerState #$VMESX = $VM.Host #$VMDisks = $VM.HardDisks Write-Output "$($VM, $Created, $User, $Event, $VMMemory, $VMCpu, $VMPowerStatus)" #Write-host "=========================================" #Write-host $VM #Write-host $Created #Write-host $Event #Write-host "=========================================" }) | Out-file C:\pscripts\output\$VIServer.csv -enc ASCII -append #disconnect-viserver $VIserver -confirm:$false