PowerCLI sccript for exporting VM details to HTML

Its a simple script for exporting VM details to HTML format. The HTML report created will be saved into the folder with the name of current month. It will help in generating a daily report with the help of Windows Task Scheduler. Refer this article for scheduling PowerCLI script.

Following details will be collected.

1. No of VMs in the vCenter.
2. No of Hosts connected in vCenter.
3. PowerState of VMs, IP address, Base ESX host, Cluster Name.

[crayon lang=”powershell”]
#Script for collecting the VM details and exporting to HTML report.

$vCenterServers = @()
$vCenterServers = “vCenter1”, “vCenter2”, “vCenter3”

$a = “

foreach ($vCenterServer in $vCenterServers)
Connect-VIServer $vCenterServer

$total_hosts = (Get-VMHost).count
$total_vms = (get-vm).count
$file_name = Get-Date -UFormat “C:\vCenterReport\$vCenterServer/%B/%Y-%b-%d @ %I-%M%p.html”

Get-VM |
select Name,Host,@{N=”Cluster”;E={@($_.host.parent.name)}}, PowerState, @{N=”IP Address”;E={@($_.guest.IPAddress[0])}} |
Sort Name | ConvertTo-Html -Head $a -Body ”

No of Hosts : $total_hosts -+- No of VMs : $total_vms

” |
Out-File -FilePath $file_name
Disconnect-VIServer $vCenterServer -Force -Confirm:$false


Report Outlook: