Help: HTML Reports for Disk Space check

This topic contains 2 replies, has 3 voices, and was last updated by  Rob Simmers 1 year ago.

  • Author
    Posts
  • #54253

    Dr3w
    Participant

    Hi all,

    I recently tried to amend my PowerShell disk space script, which previously outputted results to a text file, to instead create HTML reports. I want to make the report more presentable..

    Original code

    clear
    $file = get-Content 'X' # List of Computers
    $fileName = "X" + (Get-Date -Format dd.MM.yyyy) + ".TXT"
    
    foreach ( $node in $file) {
     get-WmiObject win32_logicaldisk -ComputerName $node | 
     ft SystemName,DeviceID,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} -autosize | Out-File $filename -append -noclobber }
    
    

    My amended code

    clear
    $file = get-Content 'X' # List of Computers
    $fileName = "X" + (Get-Date -Format dd.MM.yyyy) + ".HTML"
    foreach ( $node in $file) {
     get-WmiObject win32_logicaldisk -ComputerName $node | 
     ft SystemName,DeviceID,@{Label="Total SIze";Expression={$_.Size / 1gb -as [int] }},@{Label="Free Size";Expression={$_.freespace / 1gb -as [int] }} -autosize  | ConvertTo-HTML | Out-File $filename -append -noclobber }
    
    

    This runs fine, but there is an error in the outputted data.

    https://static.spiceworks.com/shared/post/0020/0728/BGD8Lgp.png

    Is anybody able to point me in the right direction?

    • This topic was modified 1 year ago by  Dr3w. Reason: Enclosed close block too early
    • This topic was modified 1 year ago by  Dr3w. Reason: Enclosed close block too early
  • #54256

    Daniel Krebs
    Moderator

    You'll need to replace ft (Format-Table) with Select-Object. Format-Table ends the object pipeline because it converts the objects received from Get-WmiObject into formatted text for output on a screen.

    Please find a working and formatted example of your code below:

  • #54263

    Rob Simmers
    Participant

    Also, keep in mind that disk reports are a very common requirement of administrators all over the world. There are a lot of pre-built scripts out there that perform the functionality you're asking for. Just do a search for "powershell disk space email report" and you'll find many examples of providing this functionality. Read through them and understand logically how they creating the reports.

You must be logged in to reply to this topic.