# encoding: ascii
# api: powershell
# title: MailboxFolderPermissions
# description: Enumerates mailbox folder permissions for all folders in all mailboxes
# version: 0.1
# author: themoblin
# license: CC0
# x-poshcode-id: 6627
# x-archived: 2017-03-15T18:59:12
# x-published: 2017-11-16T20:37:00
#
#
$mailboxes = get-mailbox

$mailboxes| foreach-object {
	
	$alias = $_.alias
	$folders = get-mailboxfolderstatistics $_
	$foldernames = $folders|select-object name

	"--------------------------------------------------------------" | Out-File C:\MailboxPermissions.txt -append
	"" | Out-File C:\MailboxPermissions.txt -append
	 "Processing permissions on $alias" | Out-File C:\MailboxPermissions.txt -append
	 "" | Out-File C:\MailboxPermissions.txt -append
	$foldernames | foreach-object {

		$concat = $alias + ":\" + $_.name
		get-mailboxfolderpermission -identity $concat -erroraction silentlycontinue | ft foldername,User,AccessRights | Out-File C:\MailboxPermissions.txt -append
				      }
	 "" | Out-File C:\MailboxPermissions.txt -append
	 "--------------------------------------------------------------" | Out-File C:\MailboxPermissions.txt -append
			   }
