param([string] $VISRV) #provide FQDN for vm console url $outputFile = 'C:\vminventory.csv' Add-PSSnapin -Name "VMware.VimAutomation.Core" $server = Connect-VIServer $VISRV $global:defaultVIServer = $server $Col = @() $VMs = Get-VM | Sort Name ForEach ($VM in $VMs) { $hddnum = $hddsize = $hddstore = $snapnum = $vlan = 0 $VMView = $VM | Get-View $VMNetwork = Get-NetworkAdapter -VM $VM $VMHost = Get-VMHost -VM $VM $Obj = "" | Select VM, VMHost, RAM_MB, Disks, Size_GB, Snapshots, Datastore, VLAN, IP, Notes, Url $Obj.VM = $VM.Name $Obj.VMHost = $VMHost.Name $Obj.RAM_MB = $VM.MemoryMB ForEach ($DISK in $VM.HardDisks) { $hddnum++ $Obj.Disks = $hddnum $hddsize = $hddsize+[math]::round($DISK.CapacityKB/1024/1024, 2) $Obj.Size_GB = $hddsize if ($hddstore -eq "0") {$hddstore = $DISK.Filename.Split("[]")[1]} else { $hddtemp = $DISK.Filename.Split("[]")[1] if ($hddstore -notmatch $hddtemp) {$hddstore = "$hddstore" + " + " + $DISK.Filename.Split("[]")[1]} } } if (!$hddstore) {$hddstore = "N/A"} $Obj.Datastore = $hddstore if ($VMView.Snapshot) { $snaps = $VM | Get-snapshot foreach ($snap in $snaps) {snapnum++} } $Obj.Snapshots = $snapnum Foreach ($eth in $VMNetwork) { if ($vlan -eq "0") {$vlan = $eth.NetworkName} else {$vlan = $vlan + " + " + $eth.NetworkName} } if (!$vlan) {$vlan = "N/A"} $Obj.VLAN = $vlan $VMIP = $VMVIEW.Guest.IpAddress if (!$VMIP) {$VMIP= "0.0.0.0"} $Obj.IP = $VMIP $VMNotes = $VMView.Config.annotation if (!$VMNotes) {$VMNotes= "N/A"} $Obj.Notes = $VMNotes $urlvi = $VMView.moref.value $console = "https://$VISRV/ui/?wsUrl=http://localhost:80/sdk&mo=VirtualMachine|$urlvi&inventory=none&tabs=show" $Obj.Url = $console $Col += $Obj } $Col | Export-Csv $outputFile -Delimiter ";" -NoTypeInformation $Col | ConvertTo-HTML |Set-Content c:\vminventory.html