Inherit and List Users Folder from Mailbox in Office 365 with Powershell

2023-12-18T11:48:12.15+00:00

Hello Together

I have a problem listing folders from a user's mailbox. It seems as if the shell doesn't show me all the folders, even though I can verify that the folders exist using full access.

The origin of the activity is that I have to give a user permissions to a folder and subfolders. Unfortunately the folder has subfolders and subfolders and subfolders.

Normaly a user has "inbox" and there he has the option to create new folders.

This user has made new folders above "Inbox".

User's image

Here I have already executed the following commands.

 Get-MailboxFolderStatistics ******@contoso.com -FolderScope NonIPMRoot | ft Name, FolderPath 


Get-MailboxFolderStatistics ******@contoso.com -FolderScope All | ft Name, FolderPath 




Unfortunately I can't find the folder using the following command either. The Results are empty

Get-MailboxFolderStatistics ******@contoso.com | Where { $_.FolderPath.Contains("Posteingang_LOKAL") } | ft Name, FolderPath 


How can i get the folder "Posteingang Lokal" and give user ******@contoso.com access permission to just this one folder over powershell?

Kind Regards

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Kael Yao 37,746 Reputation points Moderator
    2023-12-19T01:47:38.63+00:00

    Hi @Roman Dzichel, MP-Datentechnik GmbH,

    If the folder name is "Posteingang Lokal", there may be a typo (you have "Posteingang_LOKAL") in this cmdlet:

    Get-MailboxFolderStatistics ******@contoso.com | Where { $_.FolderPath.Contains("Posteingang_LOKAL") } | ft Name, FolderPath
    

    If you still cannot get the folder with this cmdlet, please make sure the folder name is correct and try the following script to see if it works for you:

    $path = Get-MailboxFolderstatistics -Identity ******@contoso.com | Where {$_.Name -eq "Posteingang Lokal"} | select-object -ExpandProperty FolderPath
    $path = $path -replace '/', '\'
    $path
    Add-MailboxFolderPermission -Identity ******@contoso.com:$($path) -User ******@contoso.com -AccessRights Editor
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    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.


  2. TuanNguyen-4398 0 Reputation points
    2023-12-19T08:00:14.98+00:00

    Fix support

    0 comments No comments

  3. Roman Dzichel, MP-Datentechnik GmbH 16 Reputation points
    2024-03-12T16:28:28.0866667+00:00

    For Those who will use the code in the Future

    $user = "******@contoso.com"
    $reviewer = "******@contoso.com"
    $path = Get-EXOMailboxFolderStatistics -Identity $user | Where {$_.FolderPath -like "*Posteingang_Lokal/Testordner*"} | select-object -ExpandProperty FolderPath
    $path = $path -replace '/', '\'
    foreach($folder in $path){
    	Add-MailboxFolderPermission -Identity $($user):$($folder) -User $reviewer -AccessRights Reviewer
    }
    

    delete the "XX*"*

    and everything will work fine :)

    0 comments No comments

  4. Roman Dzichel, MP-Datentechnik GmbH 16 Reputation points
    2024-03-13T09:56:05.41+00:00

    Iam Sorry to Disturb you but the code is not working.
    Wheater i get permissions on Root folder nor on subfolders.

    Maybe you can take a loook again?

    $user = "******@contoso.com"
    $reviewer = "******@contoso.com"
    $path = Get-EXOMailboxFolderStatistics -Identity $user | Where {$_.FolderPath -like "Posteingang_LOKAL/Regner Klinikum St. Marien Amberg"} | select-object -ExpandProperty FolderPath
    $path = $path -replace '/', '\'
    foreach($folder in $path){
    	Add-MailboxFolderPermission -Identity $($user):$($folder) -User $reviewer -AccessRights Reviewer 
    }
    
    
    0 comments No comments

  5. Roman Dzichel, MP-Datentechnik GmbH 16 Reputation points
    2024-03-13T10:15:25.5366667+00:00

    I have also Tried the following script for add the permissions to the folder

    Its also not working

    $requiredfoldertypes = @("Posteingang_LOKAL\DLR","Posteingang_LOKAL\Eisele Carport Esslingen","Posteingang_LOKAL\Gewürz Mayer","Posteingang_LOKAL\Regner Klinikum St. Marien Amberg ")
    
    $excludedfoldertypes = @()
    
    $accessright = “Reviewer"
    
    $users = @("Kretschmer@contoso") #,"******@contoso.com")
    
    $mbx = Get-EXOMailbox -Identity ******@contoso.com | Select-Object PrimarySmtpAddress
    
    $folderlist  = Get-EXOMailboxFolderStatistics -Identity $mbx.PrimarySmtpAddress | Select-Object Name, FolderPath, FolderType, Identity | ?{($_.FolderType -in $requiredfoldertypes) -and ($_.FolderType -notin $requiredfoldertypes) }
    
     
    
    #Then we can use either Add-MailboxFolderPermission to assign or Set-MailboxFolderPermission to modify.
    
    foreach($user in $users)
    
    {
    
        $u = Get-EXOMailbox -Identity $user | Select-Object PrimarySmtpAddress
    
        foreach($folder in $folderlist)
    
        {
    
            if($folder.FolderType -eq "Root") {$foldername = $mbx }
    
            else {$foldername = $folder.Identity.ToString().Replace([char]63743,"/").Replace($mbx.PrimarySmtpAddress.ToString(),$mbx.PrimarySmtpAddress.ToString() + ":")}
    
            $foldername
    
            Add-MailboxFolderPermission -Identity $foldername -User $u.PrimarySmtpAddress.Tostring() -AccessRights $accessright
    
            Get-MailboxFolderPermission -Identity $foldername -User $u.PrimarySmtpAddress.Tostring()
    
        }
    
    }
    
    

    Obviously the following command works Perfectly but not recursive ...

    $mailbox = "******@contos.com"
    
    $user = "******@comtoso.com"  $foldername = "Posteingang_LOKAL\AMG Erweiterung Vormontage LZM-Marbach"
    
    $folder = (Get-EXOMailboxFolderStatistics -Identity "$($mailbox)" | Where-Object { $_.FolderType -eq "Posteingang_LOKAL" }).Name
    
    Add-MailboxFolderPermission "$($mailbox):$($folder)\$($foldername)" -User "$($user)" -AccessRights "Reviewer" | Select-Object FolderName, User, AccessRights
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.