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
Try something like this
$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
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
That is gorgeous! Any chance can you add a total at the bottom?
Try something like this
$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