Converting output to GB in power shell script
The script is as shown below, the output $Date= Get-Date "Date : " + $Date.DateTime | out-file c:\temp\monthlyBillingreport.txt " " | out-file c:\temp\monthlyBillingreport.txt -Append "EmployeeID;Size"| out-file c:\temp\monthlyBillingreport.txt -Append Get-ExchangeServer | Where-Object {$_.IsMailboxserver -eq $true}| Where-Object {$_.Name -like "st-excl*" } |select Name | ForEach-Object { $csv=Get-mailbox -ResultSize Unlimited –server $_.Name | select displayname foreach ($Entry in $csv) { $MailboxStats = Get-MailboxStatistics $Entry.displayname | Select TotalItemSize $EID= get-mailbox $Entry.displayname | select customattribute12 $out = $EID.customattribute12 + ";" + $MailboxStats.TotalItemSize.Value.ToGB()| out-file c:\temp\monthlyBillingreport.txt –Append }} # end the script this does not giving me correct output. ex:if the mailbox is .400GB it just gives me 0 ex2: when the mailbox size is 1.5 gb it will only give me 1 basically it just gives me the value before the point. Regards, Exchange Admin
April 6th, 2010 8:33pm

I wrote this a while back, and Vadims help dress it up some: function to_kmg {param ($bytes,$precision='0')foreach ($i in ("Bytes","KB","MB","GB","TB")) {if (($bytes -lt 1000) -or ($i -eq "TB")){$bytes = ($bytes).tostring("F0" + "$precision")return $bytes + " $i"}else {$bytes /= 1KB}}}
Free Windows Admin Tool Kit Click here and download it now
April 6th, 2010 8:39pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics