Everything works as expected, but I have an issue with two parts of the script. They are the bits where it itterates the NIC and Hard Drives ( Pink and Blue sections below ).
Problem with the NIC loop ( Pink ) - It only shows nic 0, and if there are multiple nics - they are not output in the resulting CSV file. Also only returns NIC 0 MAC address and non of the other nic's MAC addresses.....
Problem with the disk loop ( Blue ) - it only returns the first TWO disks even though some of my VM's have 4 or even 5 disks...
Any idea why this is happening. This script is not my own work, but I have found it very useful for what I need...
Script :
Clear
$VirtualCenter = Read-Host "Please enter the name of the Virtual Center Server"
$FileLocation = Read-Host "Please Enter Complete Path and file name to save the output. Must end in .csv or .txt"
$Cred = Get-Credential
Connect-VIServer $VirtualCenter -Credential $Cred
$stats = @()
#Uncomment the next two lines if you would like to inventory just a cluster instead of all VMs in vCenter
#$VMCluster = Read-Host "Please enter the name of the HA Cluster"
#$ServerList = Get-VM -Location $VMCluster
#If the two lines abover are uncommented, then comment the next line
$ServerList = Get-VM
Foreach ($Guests in $ServerList) {
$Guest = $Guests.Name.ToUpper()
Write-Progress -Activity "Creating VMware Guest Inventory" -Status "Processing VM Guest $Guest"# Display progress bar
$VMGuest = Get-VM $Guest | Get-View
$VM = Get-VM $Guest
$ESXHost = (Get-VM $Guest).Host.Name.ToUpper()
$VMHost = get-vmhost $ESXHost | Get-View
$row = New-Object System.Object
$row | Add-Member -Type NoteProperty -Name "Guest" -Value $VMGuest.Name.ToUpper()
$row | Add-Member -Type NoteProperty -Name "Power State" -Value $VM.Guest.State
$row | Add-Member -Type NoteProperty -Name "Guest OS Full Name" -Value $VM.Guest.OSFullName
$row | Add-Member -Type NoteProperty -Name "Guest RAM (MB)" -Value $VM.MemoryMB
$row | Add-Member -Type NoteProperty -Name "Guest vCPU Count" -Value $VM.NumCPU
$row | Add-Member -Type NoteProperty -Name "Guest VMTools Status" -Value $VMGuest.Guest.ToolsStatus
$row | Add-Member -Type NoteProperty -Name "Guest VMTools Version" -Value $VMGuest.Guest.ToolsVersion
$row | Add-Member -Type NoteProperty -Name "Guest VMTools Version Status" -Value $VMGuest.Guest.ToolsVersionStatus
$row | Add-Member -Type NoteProperty -Name "Guest VMTools Running Status" -Value $VMGuest.Guest.ToolsRunningStatus
$NICCount = 0
ForEach ($vNic in $VM.Guest.Nics){
$NIC_IP = "Guest IP for NIC " + $NICCount + ""
$NIC_MAC = "Guest MAC Address for NIC " + $NICCount + ""
$NIC_vSwitch = "Guest vSwitch Network for NIC " + $NICCount + ""
$row | Add-Member -Type NoteProperty -Name $NIC_IP -Value $VMGuest.Guest.IpAddress
$row | Add-Member -Type NoteProperty -Name $NIC_MAC -Value $vNic.MacAddress
$row | Add-Member -Type NoteProperty -Name $NIC_vSwitch -Value $vNic.NetworkName
$NICCount++
}
$DiskCount = 0
$DT = @()
ForEach ($vDisk in $VM.Guest.Disks) {
$DriveLetter = "Guest Drive " + $DiskCount + ""
$DriveSize = "Guest Drive " + $DiskCount + " Size"
$DriveFree = "Guest Drive " + $DiskCount + " Free Space"
$vDiskCap = [math]::Round(($vDisk.Capacity) / 1GB)
$vDiskFree = [math]::Round(($vDisk.FreeSpace) / 1GB)
$row | Add-Member -Type NoteProperty -Name $DriveLetter -Value $vDisk.Path
$row | Add-Member -Type NoteProperty -Name $DriveSize -Value $vDiskCap
$row | Add-Member -Type NoteProperty -Name $DriveFree -Value $vDiskFree
$DiskCount++
$DriveTotals = "" + $row.$DriveLetter + " " + $row.$DriveSize + ";"
$DT += $DriveTotals
}
$row | Add-Member -Type NoteProperty -Name "Host Name" -Value $VMHost.Summary.Config.Name.ToUpper()
$row | Add-Member -Type NoteProperty -Name "# of Sessions on Host" -Value $VMHost.vm.Count
$row | Add-Member -Type NoteProperty -Name "Host is Member of Cluster" -Value (Get-Cluster -VMHost $ESXHost).Name.ToUpper()
$row | Add-Member -Type NoteProperty -Name "Host Vendor" -Value $VMHost.Hardware.SystemInfo.Vendor
$row | Add-Member -Type NoteProperty -Name "Host Model" -Value $VMHost.Hardware.SystemInfo.Model
$HostRam = [math]::Round(($VMHost.Summary.Hardware.MemorySize) / 1GB)
$row | Add-Member -Type NoteProperty -Name "Host RAM" -Value $HostRam
$row | Add-Member -Type NoteProperty -Name "Host CPU Model" -Value $VMHost.Summary.Hardware.CpuModel
$row | Add-Member -Type NoteProperty -Name "Host CPU Count" -Value $VMHost.Summary.Hardware.NumCpuThreads
$row | Add-Member -Type NoteProperty -Name "Host CPU Speed" -Value $VMHost.Summary.Hardware.CpuMhz
$row | Add-Member -Type NoteProperty -Name "Host Product Name" -Value $VMHost.Summary.Config.Product.Name
$row | Add-Member -Type NoteProperty -Name "Host Product Version" -Value $VMHost.Summary.Config.Product.Version
$row | Add-Member -Type NoteProperty -Name "Host Product Build" -Value $VMHost.Summary.Config.Product.Build
$row | Add-Member -Type NoteProperty -Name "Host Service Console" -Value $VMHost.Config.Network.ConsolevNic[0].Spec.IP.IPAddress
$row | Add-Member -Type NoteProperty -Name "Host Service Console Subnet Mask" -Value $VMHost.Config.Network.ConsolevNic[0].Spec.IP.SubnetMask
$row | Add-Member -Type NoteProperty -Name "Host Service Console 1" -Value $VMHost.Config.Network.ConsolevNic[1].Spec.IP.IPAddress
$row | Add-Member -Type NoteProperty -Name "Host Service Console 1 Subnet Mask" -Value $VMHost.Config.Network.ConsolevNic[1].Spec.IP.SubnetMask
$row | Add-Member -Type NoteProperty -Name "Host vMotion IP Address" -Value $VMHost.Config.vMotion.IPConfig.IpAddress
$row | Add-Member -Type NoteProperty -Name "Host vMotion Subnet Mask" -Value $VMHost.Config.vMotion.IPConfig.SubnetMask
$stats += $row
}
$stats | Export-Csv -Force .\$FileLocation -NoTypeInformation
Invoke-Item .\$FileLocation
Thanks for your help
PS. I'm a complete NOOB with Powercli, so trying to find my way around it still.
PPS - If anyone has an even better VM Inventory script - please be so kind as to pointing me to it....