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'