abenage
asked on
Convert bytes to megabytes
How can I convert freespace property to megabytes?
My impulse is to do something like this:
$objItem.Freespace = $objItem.Freespace / 1MB
write-host "Free Space: " $objItem.Freespace
but that does not work
Any ideas?
My impulse is to do something like this:
$objItem.Freespace = $objItem.Freespace / 1MB
write-host "Free Space: " $objItem.Freespace
but that does not work
Any ideas?
Function ListLogicalDisk {
$colItems = get-wmiobject -class "Win32_LogicalDisk" -namespace "root\CIMV2" -computer $args[0]
write-Host "Disk Information"
foreach ($objItem in $colItems) {
write-host "Description: " $objItem.Description
write-host "Device ID: " $objItem.DeviceID
write-host "Free Space: " $objItem.Freespace
write-host "Size: " $objItem.Size
write-host "Status: " $objItem.Status
write-host
}
}
The key here is understanding that $objItem.Freespace is a (read-only) property.
ASKER
OK, that makes sense, that it's read-only, but it's still not working correctly. I get a zero returned. Even if I change it to:
$Freespace = $objItem.Freespace / 2
I get a 0 returned, so I think this might be a datatype issue. Is that possible?
$Freespace = $objItem.Freespace / 2
I get a 0 returned, so I think this might be a datatype issue. Is that possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
whoops.. need to add the -computer argument back
ASKER
Perfect. Even with a label. Thanks!!!
write-host "Free Space: $FreeSpace"