Disk Space output file results not working

Welcome Forums General PowerShell Q&A Disk Space output file results not working

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #70041

    Points: 0
    Rank: Member

    Hi Guys,

    I have written up a small disk space report script to show me disk space status on my servers. Nothing ground-breaking but it does what I need it to do. It works perfectly in the console when I run it however, now I want it to output to an HTML file and eventually send it to me on a weekly basis.
    Somehow I just cant get it to output into a readable format, it seems to show up some machine code characters. Once I get the output working, I can write up the code to send an email to me which would be quite simple, but I need to fix this output issue first!
    Any ideas?
    I will continue to search the internet for similar issues but thought I'd ask here as well..

    Here is my script

    Get-WmiObject win32_logicaldisk -ComputerName $servers -Credential $cred -Filter "drivetype=3" | select PSComputerName,Name,FileSystem,VolumeName,
    @{n="Free Space in GB";e={[math]::truncate($_.freespace / 1GB)}},@{n="Size of Disk";e={[math]::truncate($_.size/ 1GB)}} | Format-table -GroupBy PSComputerName | ConvertTo-Html -CssUri 'C:\powershell\Scripts\Disk Size\style.css' -Title "Disk Report" | 
    Out-File C:\Atkins\disk.html 


  • #70051

    Points: 24
    Team Member
    Rank: Member

    You'll need to remove the Format-Table statement in your pipeline because that it does not output objects but text. ConvertTo-Html needs objects as input to create HTML documents or fragments. Format-Table is usually the last command in a pipeline used to output text to an interactive PowerShell console session.

    Try the below refactored example:

    $getWmiObjectParams = @{
        Class = 'Win32_LogicalDisk'
        ComputerName = $servers
        Credential = $cred
        Filter = 'drivetype=3'
    $selectObjectProperties = @(
            Name = "Free Space in GB"
            Expression = { [math]::truncate($_.freespace / 1GB) }
            Name = "Size of Disk"
            Expression = { [math]::truncate($_.size/ 1GB) }
    Get-WmiObject @getWmiObjectParams | 
        Select-Object -Property $selectObjectProperties |
            ConvertTo-Html -CssUri 'C:\powershell\Scripts\Disk Size\style.css' -Title "Disk Report" |
                Out-File C:\Atkins\disk.html

The topic ‘Disk Space output file results not working’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort