help with pipeline output

2021-01-14T23:04:33.403+00:00

Sorry for asking, but I have no(t much) experience with pipes in windows.

Get-MailboxFolderStatistics -Identity "shared mailbox" |?{$_.identity -like "shared mailbox\Inbox*"} | select -expand Identity

Returns this output

shared mailbox\Inbox
shared mailbox\Inbox\test
shared mailbox\Inbox\test\test2
shared mailbox\Inbox\test\test2\test21
shared mailbox\Inbox\test\test3
shared mailbox\Inbox\test\test4

How can add TrimStart('shared mailbox') to the end of this pipeline to get.

\Inbox
\Inbox\test
\Inbox\test\test2
\Inbox\test\test2\test21
\Inbox\test\test3
\Inbox\test\test4

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,503 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,906 Reputation points
    2021-01-15T03:08:58.98+00:00

    A regular expression would be one way to accomplish this. Here are three examples:

    $x = "shared mailbox\Inbox",
    "shared mailbox\Inbox\test",
    "shared mailbox\Inbox\test\test2",
    "shared mailbox\Inbox\test\test2\test21",
    "shared mailbox\Inbox\test\test3",
    "shared mailbox\Inbox\test\test4"
    
    # This way (one at a time) . . .
    $x |
        ForEach-Object{
            $_ -replace '^shared mailbox(\\.*)$', '$1'
        }
    
    # Or this way (all at once) . . .
    $x -replace '^shared mailbox(\\.*)$', '$1'
    
    # This might work, too
    $MbxName = "shared mailbox"
    (Get-MailboxFolderStatistics -Identity $MbxName |
        Where-Object {$_.identity -like "$MbxName\Inbox*"} | 
            Select-Object -expand Identity) -replace "^$MbxName(\\.*)$", '$1'
    
    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2021-01-15T00:06:23.467+00:00

    Maybe this helps:

    $output = "shared mailbox\Inbox\test"
    $output.Replace("shared mailbox","")
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Joyce Shen - MSFT 16,651 Reputation points
    2021-01-15T05:35:44.18+00:00

    Hi @FIX MY LIVE ACCOUNT FINALLY AFTER 5 MONTHS

    The script provided above from RichMatheisen-8856 should be helpful to you!

    56976-qa-2021-01-15-13-34-24.png


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
     

    0 comments No comments