Error in script : Attempted to divide by zero.

I am getting an error in my script for getting drives under 10% free space. on this line

gwmi win32_logicaldisk -ComputerName $args | Where-Object {($_.freespace/$_.size) -lt '0.10'} | ft SystemName,VolumeName
<p style="font-weight: 400;">Attempted to divide by zero.</p> <p style="font-weight: 400;">At C:\Users\robecow\Desktop\less10.ps1:42 char:61</p> <p style="font-weight: 400;">+ ... rName $args | Where-Object {($_.freespace/$_.size) -lt '0.10'} | ft S ...</p> <p style="font-weight: 400;">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p> <p style="font-weight: 400;"> + CategoryInfo : NotSpecified: (:) [], RuntimeException</p> <p style="font-weight: 400;"> + FullyQualifiedErrorId : RuntimeException</p> ##============================================================================== ## START ##============================================================================== #>
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force;
#$cre = get-Credential # This user account should be Adminstrator
$file = get-Content G:\Desktop\PS\list.txt # Replace it with your TXT file which contain Name of Computers
$OS = (gwmi win32_operatingsystem).caption
$MediaType = gwmi -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage | Select FriendlyName, MediaType
$LogicalDisks = gwmi Win32_LogicalDisk
$LocalHDisks = $LogicalDisks | Where-Object { $_.DriveType -eq 3 }
$RemoteDrives = gwmi Win32_LogicalDisk | Where-Object { $_.DriveType -eq 4 }
$OpticalDrives = gwmi Win32_CDRomDrive
$Records = 1000

ForEach ( $args in $file) {
gwmi win32_logicaldisk -ComputerName $args | Where-Object {($.freespace/$.size) -lt ‘0.10’} | ft SystemName,VolumeName,
@{n=“DriveLetter”;e={$.DeviceID}}, `
@{n=“Size(mb)”;e={[decimal]("{0:N0}" -f($
.size/1mb))}}, `
@{n=“Free Space(mb)”;e={[decimal]("{0:N0}" -f($.freespace/1mb))}} , `
@{n=“Free (%)”;e={"{0,6:P0}" -f(($
.freespace/1mb) / ($.size/1mb))}}, `
@{n=“Drive Type”;e={switch ($
.DriveType) { 0 {"(unknown)"} 2 {"(USB/FD)"} 3 {“HDD”} 4 {“SSD”} 5 {“CD/DVD/BD”} 6 {“RAM disk”}}}}, `
@{n=“Operating System”;e={$OS}}
}

Show Progress Bar - START

for($i = 1; $i -lt 101; $i++ ) {write-progress Updating progress-> -perc $i} for($i = 1; $i -lt 101; $i++ ) { write-progress Updating progress -percentcomplete $i -id 1}

Show Progress Bar - END

<#

Setup email parameters

$subject = "CIs with less than 10% freespace Report - " + $today
$body = “The Reports Completed at:$(((get-date).ToUniversalTime()).ToString(“yyyy-MM-dd”)).”
$priority = “Normal”
$smtpServer = " "
$emailFrom = “robecow@cdw.com
$emailTo = “robecow@cdw.com”;p

Setup email parameters

Send the Reports email

Send-MailMessage -To $emailTo -Subject $subject -Body $body -SmtpServer $smtpServer -From $emailFrom -Priority $priority
Write-Host “Email sent to: $emailTo at:$(((get-date).ToUniversalTime()).ToString(“yyyy-MM-dd”))”.

Send the Reports email

#>

#---------- Clean up and exit.
Write-Host “Cleanup and Exit at:$(((get-date).ToUniversalTime()).ToString(“yyyy-MM-dd”))”.
exit
#---------- Clean up and exit.

##==============================================================================

End of Script

##==============================================================================

It seems like your variable $_.size is empty … you might check if the cmdlet at the pipeline position before returns what you expect.

Win32_LogicalDisk also returns disks with no size if you have, for example, a CD drive or something. You need to make sure you account for that.