VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Dept Usage Reports

I am looking for a way to change this script from outputting a CSV to a HTML file.

Script:

$folder = 'SysDev'

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\$folder-$date.htm"

$vms = Get-Folder $folder | Get-VM

$vms | Select-Object @{e={$_.name};L="VM Name"},

@{e={$_.NumCpu};L="vCPU's"},

@{e={$_.MemoryGB};L="RAM(GB)"},

@{n="HDD Total GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},

@{n="HDD Used GB"; e={[math]::round( $_.UsedSpaceGB )}}|

Export-Csv -Path $filelocation -NoTypeInformation

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\$folder-$date.html"

$report = Get-Folder $folder | Get-VM |

Select-Object @{e={$_.name};L="VM Name"},

   @{e={$_.NumCpu};L="vCPU's"},

   @{e={$_.MemoryGB};L="RAM(GB)"},

   @{n="HDD Total GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},

   @{n="HDD Used GB"; e={[math]::round( $_.UsedSpaceGB )}}

$report += "" | Select @{L='VM Name';E={'Total'}},

@{N="vCPU's";E={$report | Measure-Object -Property "vCPU's" -Sum | select -ExpandProperty Sum}},

@{N="RAM(GB)";E={$report | Measure-Object -Property "RAM(GB)" -Sum | select -ExpandProperty Sum}},

@{N="HDD Total GB";E={$report | Measure-Object -Property "HDD Total GB" -Sum | select -ExpandProperty Sum}},

@{N ="HDD Used GB";E={$report | Measure-Object -Property "HDD Used GB" -Sum | select -ExpandProperty Sum}}


$report | ConvertTo-Html | Out-String | Out-File -FilePath $filelocation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\$folder-$date.html"

Get-Folder $folder | Get-VM |

Select-Object @{e={$_.name};L="VM Name"},

   @{e={$_.NumCpu};L="vCPU's"},

   @{e={$_.MemoryGB};L="RAM(GB)"},

   @{n="HDD Total GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},

   @{n="HDD Used GB"; e={[math]::round( $_.UsedSpaceGB )}} |

ConvertTo-Html | Out-String | Out-File -FilePath $filelocation

Invoke-Item -Path $filelocation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

That is gorgeous! Any chance can you add a total at the bottom?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="C:\util\Scripts\Temp\$folder-$date.html"

$report = Get-Folder $folder | Get-VM |

Select-Object @{e={$_.name};L="VM Name"},

   @{e={$_.NumCpu};L="vCPU's"},

   @{e={$_.MemoryGB};L="RAM(GB)"},

   @{n="HDD Total GB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},

   @{n="HDD Used GB"; e={[math]::round( $_.UsedSpaceGB )}}

$report += "" | Select @{L='VM Name';E={'Total'}},

@{N="vCPU's";E={$report | Measure-Object -Property "vCPU's" -Sum | select -ExpandProperty Sum}},

@{N="RAM(GB)";E={$report | Measure-Object -Property "RAM(GB)" -Sum | select -ExpandProperty Sum}},

@{N="HDD Total GB";E={$report | Measure-Object -Property "HDD Total GB" -Sum | select -ExpandProperty Sum}},

@{N ="HDD Used GB";E={$report | Measure-Object -Property "HDD Used GB" -Sum | select -ExpandProperty Sum}}


$report | ConvertTo-Html | Out-String | Out-File -FilePath $filelocation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos