ottojon
Contributor
Contributor

Help with HTML output for existing script

Jump to solution

I found a script that had a lot of things that I needed. I have since removed some stuff we didn't need and added some other stuff we need. The output is good, but now I want to turn this into an HTML-formatted page and it gets an error. Any help would be greatly appreciated. I'm good enough with PowerShell to be slightly dangerous with things. Smiley Happy

$Cluster = 'CLUS-1'

$ClusterName = Get-Cluster $Cluster

$Datastores = $ClusterName | Get-Datastore | Where {$_.Name -notlike '*LOCAL'  -and $_.Name -notlike 'VM_Datastore*' -and $_.Name -notlike 'Templates' -and $_.Name -notlike 'ISO' -and $_.Name -notlike '*SCRATCH*' -and $_.Name -notlike 'Archive'}

$Clusters = Get-View -ViewType ComputeResource | Where {$_.Name -like $ClusterName.Name}

$Clusters | % {

$Cluste                      = $_

$VMHostsView                 = $null

$VMHostsView                 = Get-View $Cluste.Host -Property Name, Hardware, Config

$VMss                        = $ClusterName | Get-VM

$HostCount                   = ($VMHostsView | Measure-Object).Count

$VMCount                     = 0 + ($VMss | Measure-Object).Count

$VMsPerHost                  = [Math]::Round(($VMCount/$HostCount), 1)

$vCPU                        = 0 + ($VMss | Measure-Object -Sum -Property NumCPU).Sum

$allocatedram                = 0 + ($VMss | Measure-Object -Sum -Property MemoryGB).Sum

$avgrampervm                 = [Math]::Round(($allocatedram/$VMCount), 1)

$pCPUSocket                  = ($VMHostsView | % { $_.Hardware.CPUInfo.NumCpuPackages } | Measure-Object -Sum).Sum

$TpCPUSocket                += $pCPUSocket

$pCPUCore                    = ($VMHostsView | % { $_.Hardware.CPUInfo.NumCpuCores } | Measure-Object -Sum).Sum

$vCPUPerpCPUCore             = [Math]::Round(($vCPU/$pCPUCore), 1)

$TotalClusterRAMGB           = [Math]::Round((Get-Cluster $Cluster | Get-VMHost | % { $_ } | Measure-Object -Property MemoryTotalGB -Sum).Sum)

$TotalClusterRAMusageGB      = [Math]::Round((Get-Cluster $Cluster | Get-VMHost | % { $_ } | Measure-Object -Property MemoryUsageGB -Sum).Sum)

$TotalClusterRAMUsagePercent = [Math]::Round(($TotalClusterRAMusageGB/$TotalClusterRAMGB)*100)

$TotalClusterRAMFreeGB       = [Math]::Round(($TotalClusterRAMGB-$TotalClusterRAMUsageGB))

$TotalClusterRAMReservedGB   = [Math]::Round(($TotalClusterRAMGB/100)*15)

$TotalClusterRAMAvailable    = [Math]::Round(($TotalClusterRAMFreeGB-$TotalClusterRAMReservedGB))

$newvmcountram               = [Math]::Round(($TotalClusterRAMAvailable/$avgrampervm))

$DSCount                     = 0 + ($datastores | Measure-Object).Count

$TotalDSCapacityGB           = 0 + [Math]::Round((($datastores | Measure-Object -Sum -Property CapacityGB).Sum), 0)

$TotalDSFreeGB               = 0 + [Math]::Round((($datastores | Measure-Object -Sum -Property FreespaceGB).Sum), 0)

$TotalDSUsedGB               = [Math]::Round(($TotalDSCapacityGB - $TotalDSFreeGB),0)

$allocatedstorage            = 0 + ($VMss | Measure-Object -Sum -Property ProvisionedSpaceGB).Sum

$avgstoragepervm             = [Math]::Round(($allocatedstorage/$VMCount), 1)

$newvmcountstorage           = [Math]::Round(($TotalDSFreeGB/$avgstoragepervm))

New-Object PSObject |

Add-Member -Pass NoteProperty "Cluster Name" $ClusterName.Name |

Add-Member -Pass NoteProperty "Cluster - Host Count" $HostCount |

Add-Member -Pass NoteProperty "Cluster - VM Count" $VMCount |

Add-Member -Pass NoteProperty "Cluster - VM per Host" $VMsPerHost |

Add-Member -Pass NoteProperty "Compute - Number of pCPU" $TpCPUSocket |

Add-Member -Pass NoteProperty "Compute - pCPU per Core" $pCPUCore |

Add-Member -Pass NoteProperty "Compute - Number of vCPU" $VCPU |

Add-Member -Pass NoteProperty "Compute - vCPU per pCore" $vcpuperpcpucore |

Add-Member -Pass NoteProperty "Compute - Total Memory (GB)" $TotalClusterRAMGB |

Add-Member -Pass NoteProperty "Compute - Total Memory Used (%)" $TotalClusterRAMUsagePercent |

Add-Member -Pass NoteProperty "Compute - Total Memory Used (GB)" $TotalClusterRAMusageGB |

Add-Member -Pass NoteProperty "Compute - Total Memory Free (GB)" $TotalClusterRAMfreeGB |

Add-Member -Pass NoteProperty "Compute - Total Memory Allocated (GB)" $TotalClusterRAMReservedGB |

Add-Member -Pass NoteProperty "Compute - RAM Available for NEW VMs (GB)" $TotalClusterRAMAvailable |

Add-Member -Pass NoteProperty "Compute - Average RAM allocated per VM" $avgrampervm |

Add-Member -Pass NoteProperty "Compute - Remaining VMs based on available RAM" $newvmcountram |

Add-Member -Pass NoteProperty "Storage - Datastore Count" $DSCount |

Add-Member -Pass NoteProperty "Storage - Total Datastore Capacity (GB)" $TotalDSCapacityGB |

Add-Member -Pass NoteProperty "Storage - Total Datastore Free (GB)" $TotalDSFreeGB |

Add-Member -Pass NoteProperty "Storage - Total Datastore Used (GB)" $TotalDSUsedGB |

Add-Member -Pass NoteProperty "Storage - Average storage allocated per VM" $avgstoragepervm |

Add-Member -Pass NoteProperty "Compute - Remaining VMs based on available storage" $newvmcountstorage

}

0 Kudos
1 Solution

Accepted Solutions
kunaludapi
Expert
Expert

on the very last line of the script after } add below line

| ConvertTo-Html | Out-File c:\log.html

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

View solution in original post

0 Kudos
6 Replies
ottojon
Contributor
Contributor

By the way, the current output looks like this:

Cluster Name                                  :CLUS-1
Cluster - Host Count                          : 3
Cluster - VM Count                            : 40
Cluster - VM per Host                         : 13.3
Compute - Number of pCPU                      : 72
Compute - pCPU per Core                       : 36
Compute - Number of vCPU                      : 122
Compute - vCPU per pCore                      : 3.4
Compute - Total Memory (GB)                   : 384
Compute - Total Memory Used (%)               : 35
Compute - Total Memory Used (GB)              : 134
Compute - Total Memory Free (GB)              : 250
Compute - Total Memory Allocated (GB)         : 58
Compute - RAM Available for NEW VMs (GB)      : 192
Compute - Average RAM allocated per VM        : 6.6
Compute - Remaining VMs based on available RAM : 29
Storage - Datastore Count                     : 12
Storage - Total Datastore Capacity (GB)       : 6897
Storage - Total Datastore Free (GB)           : 3684
Storage - Total Datastore Used (GB)           : 3213
Storage - Average storage allocated per VM    : 81.2

Storage - Remaining VMs based on available storage : 45

0 Kudos
kunaludapi
Expert
Expert

on the very last line of the script after } add below line

| ConvertTo-Html | Out-File c:\log.html

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
ottojon
Contributor
Contributor

Thanks kunaludapi. I think I simply forgot the pipe when I originally wrote it and didn't think twice about such a simple mark when I was attempting to troubleshoot. I now feel stupid for even posting the question! Sigh. Smiley Happy Thanks again.

0 Kudos
ottojon
Contributor
Contributor

Actually, one more question. The output generates a ton of columns rather than rows. The above output (text) is formatted as one big list. Any ideas how to get the values defined in the "Add-Member" statements to be rows instead of columns?

0 Kudos
kunaludapi
Expert
Expert

Have a look at it, i use the same way to create website based inventory.

http://technet.microsoft.com/en-us/magazine/hh824687.aspx

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
ottojon
Contributor
Contributor

I just figured it out with the existing modifications. ConvertTo-HTML has a LIST option, so: ConvertTo-HTML -As LIST

It is not a preferred method for conversion, but it works for me Smiley Happy Thanks again!

0 Kudos