I can't work out why the script is calculating the disk freespace storage correctly but issues the "Attempted to divide by zero" error on execution. Can anyone shed light on this? I know that there are other more efficient ways to get the percentage but I'm determined to crack this one!
Get-WmiObject Win32_LogicalDisk -ComputerName "*servername*" |
ForEach-Object {
'Disk {0} has {1:0.0} GB space available out of {2:0.0} GB {3:p0} Freespace' -f $_.Caption, ($_.FreeSpace / 1GB), ($_.Size / 1GB), ($_.Freespace / $_.Size)
}
Disk C: has 30.9 GB space available out of 79.7 GB 39%
Disk E: has 18.8 GB space available out of 20.0 GB 94%
Disk L: has 332.2 GB space available out of 377.0 GB 88%
Attempted to divide by zero.
At line:3 char:1
'Disk {0} has {1:0.0} GB space available out of {2:0.0} GB {3:p0} '
CategoryInfo : NotSpecified: (:) [], RuntimeException FullyQualifiedErrorId : RuntimeException