Link to home
Start Free TrialLog in
Avatar of abenage
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?

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
}
}

Open in new window

Avatar of BSonPosh
BSonPosh
Flag of United States of America image

$Freespace = $objItem.Freespace / 1MB
write-host "Free Space: $FreeSpace"
The key here is understanding that $objItem.Freespace is a (read-only) property.
Avatar of abenage
abenage

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?
ASKER CERTIFIED SOLUTION
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
whoops.. need to add the -computer argument back
Avatar of abenage

ASKER

Perfect.  Even with a label.  Thanks!!!