Forum Discussion

JimBlunt's avatar
JimBlunt
Brass Contributor
Sep 07, 2023
Solved

Recursive Script to Get/Set/Remove Exchange Mailbox Folder Permissions

Okay, I have a tiny issue.  I'm okay at PS scripting, not a guru by any stretch of the imagination.  So here's the situation.   Situation: Mailbox needs to move from on-prem to Exchange Online.  ...
  • JimBlunt's avatar
    JimBlunt
    Sep 11, 2023

    LeonPavesic Over the weekend, I found something that works for me and it's only 6 lines of code.  So, in the first 4 lines of code:

    • $Alias = Read-Host "Please enter the mailbox alias"
    • $Folders = Get-MailboxFolderStatistics -Identity $Alias | Where-Object {$_.FolderType}
    • $FolderID = ForEach ($F in $Folders) {$Alias + ":" + $F.FolderID}
    • $Perms = ForEach ($F in $FolderID) {Get-MailboxFolderPermission -Identity $F}

     

    Once I take the output from $Perms and condense it down to a usable user list, I can run the last two:

    • $Users = Get-Content "C:\Temp\Users.txt"
    • ForEach ($F in $FolderID) {ForEach ($U in $Users) {Remove-MailboxFolderPermission $F -User $U -Confirm:$false | Write-Host $F}}

Resources