Author Posts

December 14, 2017 at 3:25 pm

Hi

I'm trying to run :

$servers = get-content "C:\Computers.txt"
gwmi Win32_LogicalDisk -ComputerName $servers | where {$_.freespace/$_.size * 100 -lt 15} |FT PSComputerName,DeviceID, @{n='Size(GB)';e={$_.size / 1gb -as [int]}},@{n='Free(GB)';e={$_.Freespace / 1gb -as [int]}} ,@{l='%FreeDiskSpace';e={($_.FreeSpace / $_.Size)*100 -as [int]}}

and I get "Attempted to divide by zero message" message on the spot before the first "$_.freespace".

December 14, 2017 at 3:29 pm

Freespace is zero on many kinds of drives, like a DVD. Size can also be zero on some drives.

December 14, 2017 at 4:26 pm

use

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"

if you just want the hard drives

December 20, 2017 at 5:05 pm

Thanks . Its ok now