Remove bytes from sizes / create column?

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 4 months ago.

  • Author
    Posts
  • #5844

    by nharvey at 2013-04-24 08:22:20

    GM all,

    when I run Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto the output looks great, but is there a way to get rid of the bytes number, so it just shows the size in GB?

    Here's an example:
    Name DatabaseSize AvailableNewMailboxSpace
    ---- ------------ ------------------------
    IT 18.38 GB (19,738,460,160 bytes) 38.19 MB (40,042,496 bytes)

    The goal would be to easily export and run calculations on it.
    Thank you in advance for any help!

    by ArtB0514 at 2013-04-24 09:15:58

    One way would be to do this:
    Get-MailboxDatabase -Status |
    Format-Table name,databasesize,@{Name='AvailableSpace';Expression={($_.availablenewmailboxspace.Split(' ('))[0]}} -AutoSize

    by mjolinor at 2013-04-24 09:23:27

    There's two different solutions to that problem, and which one you need to use is going to depend on the environment you're running the command in.

    If you're running from an EMS shell, those Value properties should have a .ToBytes() method that will produce an int byte count that you can use with math operations.

    If you're running in an implicit remoting session, then what you got back was a deserialized object with no methods, and that property is just a string and you'll have to parse the byte count out of the string.

    -replace '.+\((.+)\)','$1' -replace '\D'

    by ArtB0514 at 2013-04-24 11:24:18

    [quote]If you're running in an implicit remoting session, then what you got back was a deserialized object with no methods, and that property is just a string and you'll have to parse the byte count out of the string.[/quote]

    Sorry, that's what I was doing and should have said so.

    by nharvey at 2013-04-24 15:01:18

    Thank you both for the responses.

    Art,
    Your command shows this:
    [PS] C:\Windows\system32>Get-MailboxDatabase -Status | Format-Table name,databasesize,@{Name='AvailableSpace';Expressio
    ={($_.availablenewmailboxspace.Split(' ('))[0]}} -AutoSize

    Name DatabaseSize AvailableSpace
    ---- ------------ --------------
    IT 18.51 GB (19,872,677,888 bytes)

    And sorry Mjol,
    Where do I add that line of code?

    by mjolinor at 2013-04-24 15:08:46

    Like this:

    Get-MailboxDatabase -Status |
    ft Name,
    @{l='DB_Size';e={$_.DatabaseSize -replace '.+\((.+)\)','$1' -replace '\D'}},
    @{l='AvailableSpace';e={$_.AvailableNewMailboxSpace -replace '.+\((.+)\)','$1' -replace '\D'}} -AutoSize

You must be logged in to reply to this topic.