Cut string after specific characters occurence

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

  • Author
    Posts
  • #5370

    by PowerFree at 2012-12-20 01:01:46

    Hi Folks,

    I am doing some PowerShell reporting for our mail server with Exchange Management console. I am querying for Quota properties on mailboxes and the output is like:

    $IssueWarningQuota = 4 GB (4,294,967,296 bytes)
    or
    $IssueWarningQuota = 4.199 GB (4,508,876,800 bytes)

    I would like to get rid of everything following GB

    so "4 GB (4,294,967,296 bytes)" would become "4 GB"
    and "4.199 GB (4,508,876,800 bytes)" would become "4.199 GB"

    by nohandle at 2012-12-20 01:18:38

    try this:

    $string = "4 GB (4,294,967,296 bytes)"
    if ($string -match ".*GB")
    {
    $matches[0]
    }

    by PowerFree at 2012-12-20 02:29:12

    HI,

    I tried the following:
    [code2=powershell]$mbstats = get-mailbox $mb | where {$_.UseDatabaseQuotaDefaults -eq $False} | ft name,prohibit*,issue*
    if ($mb.IssueWarningQuota -match ".*GB")
    {
    $mb.IssueWarningQuota = $mb.IssueWarningQuota[0]
    }

    $userObj | Add-Member NoteProperty IssueWarningQuota -Value $mb.IssueWarningQuota
    $userObj | Add-Member NoteProperty ProhibitSendQuota -Value $mb.ProhibitSendQuota
    $userObj | Add-Member NoteProperty ProhibitSendReceiveQuota -Value $mb.ProhibitSendReceiveQuota[/code2]

    But it still returns "4 GB (4,294,967,296 bytes)"

    by nohandle at 2012-12-20 03:31:55

    The resulting value is saved in the $matches[0] not in $mb.IssueWarningQuota[0].
    Does this work?
    $mb.IssueWarningQuota = $matches[0]

    by PowerFree at 2012-12-20 04:50:05

    It works! thanks a lot

    by nohandle at 2012-12-20 05:55:39

    You are welcome. If the issue is solved please mark the thread as solved by the solved button.

You must be logged in to reply to this topic.