Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've created a script to get hard drive information from our servers. The script use WMI to query the Win32_LogicalDisk class and returns "Size (GB)", "Free Space (GB)" and "Free Space (%)" for each device ID (local disk) of each server.

I want to sort by "Free Space (%)" for every device ID on each server. When I sort by "Free Space (%)", it does not show every device ID. One server has both C: and D: drives, but only the D: drive is shown in the output. If I remove the Sort-Object "Free Space (%)" it will show all device IDs for each server.

Can anyone help me with this script?

$computers   = C:\users\mtrajano\documents\powershell\scripts\list.txt
$logicalDisk = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" -Computer $computers |
    Select-Object SystemName, DeviceID,
        @{ Name = "Size (GB)";       Expression = { "{0:N1}" -f ($_.size / 1GB) } },
        @{ Name = "Free Space (GB)"; Expression = { "{0:N1}" -f ($_.freespace / 1GB) } },
        @{ Name = "Free Space (%)";  Expression = { "{0:P2}" -f (($_.freespace / 1GB) / ($_.size / 1GB)) } } |
            Sort-Object "Free Space (%)" |
                ConvertTo-Html |
                    Out-String

$messageParameters = @{
    To          = ""
    From        = ""
    Subject     = ""
    Body        = $logicalDisk
    SmtpServer  = ""
}

Send-MailMessage @messageParameters -BodyasHtml
share|improve this question
    
Im new to the here. I will see how I can format it better so that I can get help thanks. –  Charlie Lopez May 1 '13 at 19:12
    
Thanks Jscott for reformatting the look of my script. I hope someone can help me. –  Charlie Lopez May 1 '13 at 19:21
1  
I've ran this against all our capable Windows servers. I'm getting the same counts (using Measure-Object) whether I Sort-Object "Free Space (%)" or not. Could you provide some example output of the issue? Is it possible a machine was temporarily inaccessible via WMI between the two runs of this script? –  jscott May 1 '13 at 19:59
    
sure I can provide some output examples of the issue. Not sure how to attach a picture –  Charlie Lopez May 1 '13 at 20:32
    
Im not sure how to attach a picture here to show you Jscott –  Charlie Lopez May 1 '13 at 20:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.