Convert % free disk space to HTML

Hello,

I have this script where I get the disk information and convert it to HTML.
When I do not copnvert this to HTML , I get the correct values on screen.
Only when I convert this to HTML it shows me the labels and the diskspace in a full number.
The Disk % is not shown in the HTML report.

My skills are not grown up enough to fix this or figure this out at the moment, I appreciate any help.

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -Class win32_LogicalDisk -ComputerName $Computername | Select-Object @{Name="Size(GB)";Expression={$_.size/1gb}},`
@{Name="Free Space(GB)";Expression={$_.freespace/1gb}}, @{Name="Free_(%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb)`
/ ($_.size/1gb))}}, DeviceID, DriveType, SystemName,VolumeName,freespace| Where-Object DriveType -EQ '3' |
 ConvertTo-Html -As table -Property DeviceID,VolumeName,FreeSpace,Free_% -PreContent "<h2>Disk Information</h2>" -Fragment 

 ConvertTo-HTML -Body "$ComputerName $DiscInfo"`
 -Head $header -Title "Computer Information Report" -PostContent "<p id='CreationDate'>Engineer : $Engineer , Creation Date: $(Get-Date)</p>"|
  Out-File .\Report\AIS-Disc.html

The picture shows the output.
Because it is a part of a larger script it has a -fragment and a separate ConvertTo-html .
This is to make sure it is the same behavior as in the full script.

thank you for any help.

Your code is obviously broken. Could you please refomat it nicely and post it again. Please do not create a new post - correct your existing one.

Thanks in advance

1 Like

You use different property names. Once the name is “Free_(%)” and later it is “Free_%”.

Something like this should work actually:

$DiscInfo = 
Get-CimInstance -Class win32_LogicalDisk -ComputerName $Computername | 
Where-Object DriveType -EQ '3' |
Select-Object DeviceID, VolumeName, freespace, 
    @{Name="Free_%";Expression={'{0,6:P0}' -f (($_.freespace / $_.size))}} | 
     ConvertTo-Html -As table -PreContent "<h2>Disk Information</h2>" -Fragment 

 ConvertTo-HTML -Body "$ComputerName $DiscInfo" -Head $header -Title "Computer Information Report" -PostContent "<p id='CreationDate'>Engineer : $Engineer , Creation Date: $(Get-Date)</p>" |
  Out-File .\Report\AIS-Disc.html

Your formatting is atrocious. I urgently recommend to read the

Hi Olaf,

Thank you very much for the reply, yes I agree about the formatting in this post .
I will review my writing and look at your link at github.

Your suggestion works well exactly, I realy appreciate this.
:+1: