techdrive
asked on
Converting data to KB, MB, GB
I have been trying to convert raw numbers in a file to KB, GB or MB. For ex
get-content c:\temp\numbers.txt | select -object Name, {$_.Somename.value.ToMB()}
the text file contain numbers of different sizes that were recorded from another sheet.
or I would really like to pipe it into something like this
$_ | Select-Object Name, @{n='Count';e={ $Count }}, @{n='Size';e={
If ($Size -gt 1GB) { "$('{0:N2}' -f ($Size / 1Gb)) GB" }
ElseIf ($Size -gt 1MB) { "$('{0:N2}' -f ($Size / 1Mb)) MB" }
ElseIf ($Size -gt 1KB) { "$('{0:N2}' -f ($Size / 1Kb)) KB" }
Else { "$Size b" } }}
get-content c:\temp\numbers.txt | select -object Name, {$_.Somename.value.ToMB()}
the text file contain numbers of different sizes that were recorded from another sheet.
or I would really like to pipe it into something like this
$_ | Select-Object Name, @{n='Count';e={ $Count }}, @{n='Size';e={
If ($Size -gt 1GB) { "$('{0:N2}' -f ($Size / 1Gb)) GB" }
ElseIf ($Size -gt 1MB) { "$('{0:N2}' -f ($Size / 1Mb)) MB" }
ElseIf ($Size -gt 1KB) { "$('{0:N2}' -f ($Size / 1Kb)) KB" }
Else { "$Size b" } }}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What exactly do you have in that text file of yours?
Chris
Chris
ASKER
Chris sorry the machine I was using is locked down. This worked perfectly thanks again.
ASKER
Cannot compare "@{Name=439150512}" to "1073741824" because the objects are not the same type or the object "@{Name=439150512}" does not implement "IComparable".
At C:\temp\convert.ps1:2 char:13
+ If ($_ -gt <<<< 1GB) {
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemExceptio
+ FullyQualifiedErrorId : PSObjectCompareTo