none
Powershell - Get mailbox folder permission for a specific folder in multiple mailboxes RRS feed

  • Question

  • Hello and thank you for your assistance. We are using Exchange Online aka O365. I am looking to create a powershell script which does the following:

    1. Inputs a list of mailbox identities from a CSV/TXT file

    2. Exports the folder permissions for folders in each of those mailboxes to a CSV file including ONLY folders named either "Secure" or "Private"

    The folders are not in the exact same location in each mailbox, i.e. some have a folder called "Secure" as a root folder, others as a subfolder of Inbox, etc.

    I am currently doing this one mailbox at a time and cannot get it to filter out the folders that aren't called "Secure" or "Private".

    Any assistance is appreciated.

    This is what I am using currently:

    $mailbox=get-mailbox -identity username@domain.com
    
    foreach($mbx in $mailbox)
    
    
    {
    
    $folders=Get-MailboxFolderStatistics -Identity $mbx.Name | Where {{$_.foldername -eq '\Secure'} -or {$_.foldername -eq '\Private'}} | select -ExpandProperty folderpath 
    
    
    
    foreach($folder in $folders)
    {
    
     $path=$folder.replace("/","\")
    
     $name=$mbx.name
     
     Get-MailboxFolderPermission -Identity "${name}:$path" -ErrorAction silentlycontinue | Export-Csv C:\temp\permissions.csv -Append
    
     }
     } 

    The script works, however the folder name filters don't seem to be applying and I can only do it one mailbox at a time.


    • Edited by EJ72 Thursday, January 3, 2019 8:25 PM spelling
    Thursday, January 3, 2019 8:24 PM

Answers

All replies

  • The property you need to filter on is Name, not FolderName. Or you can just filter on FolderPath
    Thursday, January 3, 2019 8:46 PM
  • I have tried many iterations of different filters but they do not seem to be having any effect. It is probably something obvious, but if I change the line as shown below, I still get every single folder in the mailbox showing up in the CSV:

    $folders=Get-MailboxFolderStatistics -Identity $mbx.Name | Where {{$_.name -eq '\Secure'} -or {$_.name -eq '\Private'}} | select -ExpandProperty folderpath 

    There is no filtering, I get all 147 folders for that particular mailbox, including archive, calendar, contacts, etc.

    Thursday, January 3, 2019 8:54 PM
  • Try it with proper brackets:

    $folders=Get-MailboxFolderStatistics -Identity $mbx.Name | Where {($_.name -eq '\Secure') -or ($_.name -eq '\Private')} | select -ExpandProperty folderpath 

    Or just use the script here: https://gallery.technet.microsoft.com/Office-365-Mailbox-Folder-17251cab?redir=0

    • Marked as answer by EJ72 Monday, January 7, 2019 5:58 PM
    Thursday, January 3, 2019 9:03 PM
  • Thank you, changing the brackets to parentheses solved the filtering issue.

    Does anyone know how to further modify the script to accept a list of mailboxes in a txt or csv file?

    Unfortunately the linked script does not have that capability.

    Thursday, January 3, 2019 9:11 PM
  • Thank you, changing the brackets to parentheses solved the filtering issue.

    Does anyone know how to further modify the script to accept a list of mailboxes in a txt or csv file?

    Unfortunately the linked script does not have that capability.

    The script below works fine in my lab, it accepts a list of mailboxes in a csv file.

    Get-Mailbox | select @{Expression={$_.displayname};Label="mbx";} | Export-Csv c:\temp\mailboxlist.csv -NoTypeInformation
    
    $mailbox= Import-Csv c:\temp\mailboxlist.csv
    
    foreach($mbx in $mailbox)
    
    ......


    Regards,

    Manu Meng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, January 4, 2019 6:31 AM
    Moderator
  • Thank you for the suggestion, however this will get EVERY mailbox in the organization. I was hoping to be able to provide a preset list of usernames/email addresses in a file and only have those mailboxes run through the folder permission script. The users in question are spread out among multiple locations and business units so there is no common, "searchable" criteria among them that could be used in a filter, thus the need to provide a list of mailboxes in a CSV file instead.
    Friday, January 4, 2019 2:20 PM
  • Thank you for the suggestion, however this will get EVERY mailbox in the organization. I was hoping to be able to provide a preset list of usernames/email addresses in a file and only have those mailboxes run through the folder permission script. The users in question are spread out among multiple locations and business units so there is no common, "searchable" criteria among them that could be used in a filter, thus the need to provide a list of mailboxes in a CSV file instead.

    Since there is no common property for these users, we couldn't use the -Filter patameter to filter the recipients. The best way so far is manually adding the a custom attribute for these users' mailbox and then filter the mailbox through it. 

    Regards,

    Manu Meng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, January 7, 2019 9:35 AM
    Moderator
  • I guess I'll just keep doing it the manual way. Thanks to all for their assistance.
    Monday, January 7, 2019 5:58 PM