Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

Help with calculating the percentage of disk used in a powershell script

Hello Powershell Experts,

Im still farily new to both Powershell and scripting in general.  To help myself learn Powershell, I have decided to not only read as much about the topic as possible, but also try to write some scripts that would actually be useful at work.  The first script Im working on is a simple script that will be run every morning that will display the following table:


Server          Drive          Free Space (GB)          Total Disk Space (GB)     Percent Used

I have run the get-help and get-member on the get-wmiobject win32_logicaldisk commandlet and figured out how to get everything except the Percent Used.  Im hoping you all can help me with that part.  Here is the code I have so far:

Get-WmiObject win32_logicaldisk -ComputerName (get-content "c:\Systems Administration\Scripts\Servers.txt") -filter "drivetype=3" | `
Format-Table @{lABEL="SERVER";EXPRESSION={$_.SYSTEMNAME}}, `
@{label="Drive Letter";Expression={$_.DeviceID}}, `
@{label="Free Space on Disk (GB)";expression={"{0:n2}" -f($_.freespace/1gb)}}, `
@{label="Total Disk Space (GB)";expression={"{0:n2}" -f($_.size/1gb)}}


I think what I have to do is declare two variables ($freeSpace and $TotalSize) then just do the math, but Im not sure.  Any help would be greatly appreciated.

Regards,
Nick
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ndalmolin_13

ASKER

This works great!!!   Thanks for your help.  I'm hoping I can pick your brain for a bit.  Believe it or not, I was pretty close at one point.  I really apprecieate the help.

Thanks,
Nick
Never mind about picking your brain.  I found an article that explained my question.  Thanks again.