Attempted to divide by zero message

This topic contains 3 replies, has 3 voices, and was last updated by  Arik Cher 4 months ago.

  • Author
    Posts
  • #89230

    Arik Cher
    Participant

    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".

  • #89231

    Don Jones
    Keymaster

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

  • #89240

    Richard Siddaway
    Moderator

    use

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

    if you just want the hard drives

    • #89747

      Arik Cher
      Participant

      Thanks . Its ok now

You must be logged in to reply to this topic.