Question : 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?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
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 Select All

Answer : Convert bytes to megabytes

Try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Function ListLogicalDisk {
$colItems = get-wmiobject -class "Win32_LogicalDisk" -namespace "root\CIMV2"
write-Host "Disk Information"
foreach ($objItem in $colItems) {
write-host "Description: " $objItem.Description
write-host "Device ID: " $objItem.DeviceID
write-host "Free Space: " ("{0:n2} MB" -f ($objItem.Freespace/1mb))
write-host "Size: " $objItem.Size
write-host "Status: " $objItem.Status
write-host
}
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us