Bart’s Weblog

Just a blog…

PowerShell: How to retrieve disk size & free disk space for a list of computers (input file)

Posted by bartvdw on June 19, 2008

Note: works only with V2 which is currently in CTP stage!

The command below will show you a very nice overview of disk size & free space for a list of computers (input file). The great thing about PowerShell, from my point of view, is “piping” commands into 1 big command which eliminates the need to create a script for certain operations. Secondly in V2 (CTP), the “gridview” option is amazing!

Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -computer (Get-Content c:\scripts\computers.txt) | Select SystemName,DeviceID,VolumeName,@{Name=”size(GB)”;Expression={”{0:N1}” -f($_.size/1gb)}},@{Name=”freespace(GB)”;Expression={”{0:N1}” -f($_.freespace/1gb)}} | Out-GridView

4 Responses to “PowerShell: How to retrieve disk size & free disk space for a list of computers (input file)”

  1. ghanshyam said

    wow! Thats a awesome script

  2. abdul said

    thanks for the script…works great…how do i get this to output to a file and send an email to myself?

    I tried to pipeline to csv or txt…but it failed. shouldnt it just be this:

    Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -computer (Get-Content c:\scripts\computers.txt) | Select SystemName,DeviceID,VolumeName,@{Name=”size(GB)”;Expression={”{0:N1}” -f($_.size/1gb)}},@{Name=”freespace(GB)”;Expression={”{0:N1}” -f($_.freespace/1gb)}} | Export-CSV drivesizes.csv

    $msg = new-object Net.Mail.MailMessage
    $att = new-object Net.Mail.Attachment($filename)
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)

    $msg.From = “admin”
    $msg.To.Add(”admin”)
    $msg.Subject = “drive size”
    $msg.Body = “The drive size file is attached”
    $msg.Attachments.Add($att)

    $smtp.Send($msg

    Am I missing something? any help will be appreciated…thanks.

  3. Ray said

    Get-WMIObject Win32_LogicalDisk -filter “DriveType=3″ -computer (Get-Content c:\computers.txt) | It’s not working for me… what am I doing wrong. I have version 2.

    Select SystemName,DeviceID,VolumeName,@{Name=”size(GB)”;Expression={”{0:N1}” -f($_.size/1gb)}},@{Name=”freespace(GB)”;Expression={”{0:N1}” -f($_.freespace/1gb)}} | Out-GridView
    Unexpected token ‘:N1′ in expression or statement.
    At line:1 char:169

    Unexpected token ‘:N1′ in expression or statement.
    At line:1 char:231

    Encountered end of line while processing a string token.
    At line:1 char:274

  4. Ray said

    Figured it out. The script didn’t copy over properly.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>