In Powershell, I would like to convert $size variable from bytes into GB gigabytes. What is the best way to do it? So far I have the following script:
$dir = "C:\Users\student"
$count = @{}
$size = @{}
$hostname = @{}
gci $dir -recurse |%{
[int]$count[$_.extension] += 1
[int64]$size[$_.extension] += $_.length
}
$results = @()
$count.keys | sort |% {
$result = ""|select extension,count,size,hostname
$result.extension = $_
$result.count = $count[$_]
$result.size = $size[$_]
$result.hostname = $(get-content env:computername)
$results += $result
}
$results | ft -auto
$results | sort-object -property size -Descending | select-object -first 30| export-csv c:\"$env:computername-$(get-date -f dd-MM-yyyy-HH-mm)".csv
there is a trick for it
$result.size = $size[$_] /1Gb
and if you want better view for results you can truncate it
$result.size = [math]::round($size[$_] /1Gb, 3)
http://technet.microsoft.com/en-us/library/ee692684.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With