ndalmolin_13
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\Ser vers.txt") -filter "drivetype=3" | `
Format-Table @{lABEL="SERVER";EXPRESSIO N={$_.SYST EMNAME}}, `
@{label="Drive Letter";Expression={$_.Dev iceID}}, `
@{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
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\Ser
Format-Table @{lABEL="SERVER";EXPRESSIO
@{label="Drive Letter";Expression={$_.Dev
@{label="Free Space on Disk (GB)";expression={"{0:n2}"
@{label="Total Disk Space (GB)";expression={"{0:n2}"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Never mind about picking your brain. I found an article that explained my question. Thanks again.
ASKER
Thanks,
Nick