Share Users Folder from Mailbox in Office 365 with Powershell EXO

2024-03-14T13:26:24.1833333+00:00

Dear Ladies and Gentleman

Iam Trying to complete my task with the following code and situation.

A user has a lot of folders in his mailbox. Some of them should be shared with other users from the same domain.

With the actual code which should work, i actually don`t get the goal. I also don't get any Errors in Powershell ISE.

But the Permission will ne be set.

Does somebody can help me in this situation?

$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()

    }

}



Oviously the follow command works like a charm but without inheritance.

$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



Maybe somebody had already the problem and could help me?

Kind Reagrds.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,178 questions
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 119.6K Reputation points MVP Volunteer Moderator
    2024-03-17T02:23:38.77+00:00

    What exactly is the Posteingang_LOKAL folder? You cannot use the cmdlet to grant permissions to any local folder (i.e. ones exposed from an opened PST), if that's what you are after.

    If you want to run this only for subfolders of a specific folder, use the -ParentFolderPath parameter as explained in: https://www.michev.info/blog/post/5763/managing-mailbox-folder-permissions-in-bulk-in-microsoft-365


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.