Get MailboxFolderPermission script to CSV - Exchange 2010

Jaime Umali
Jaime Umali used Ask the Experts™
on
Hi guys, I'm creating a report gathering user's mailbox folder delegation i already have the following data:
Mailbox,DelagateUser,Foldername,AccessRights,

what I need as final report is this:
Mailbox,Alias(alias of mailbox),DelegateUser(alias of delegate user),City,Department,FolderName,AccessRights

I need this on a CSV.

Thanks guys for continuous help!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Manikandan NarayanswamySecurity Specialist & IBM Security Guardium

Commented:
Hi,

Try to use command like this and let me know if you face any issue

Get-Mailbox | Get-MailboxPermission | Where { $.IsInherited -eq $False } | Select Alias,City,Department,FolderName {$.AccessRights},Deny | Export-Csv C:\export.csv

Thanks
Manikandan

Author

Commented:
thanks Manikandan,  but rather I need "Get-mailboxFolderPermission"

my script runs like this:
$allfolders = @()

$DB1 = Get-mailbox "mailbox_owner"

ForEach ($Alias in $DB1)
{
$Mailbox = "" + $Alias.DisplayName
Write-Output $Mailbox
$mb = @{Expression={$Alias.DisplayName};Label="Mailbox"}
$Folders = Get-MailboxFolderStatistics $Mailbox | % {$_.folderpath} | % {$_.replace(“/”,”\”)}

ForEach ($F in $Folders)
{
$FolderKey = $Mailbox + ":" + $F
$Permissions = Get-MailboxFolderPermission -identity $FolderKey -ErrorAction SilentlyContinue
$add = $Permissions | Where-Object {$_.User -notlike "Default" -and $_.User -notlike "Anonymous" -and $_.AccessRights -notlike "None" -and $_.AccessRights -notlike "Owner" -and $_.User -NotMatch "NT"}| Select $mb,@{Expression={$_.User};Label="DelegateUser"},FolderName,@{Expression={$_.AccessRights};Label="AccessRights"}
$allfolders += $add

}
}

$allfolders | Where-Object {$_} | Export-Csv "D:\MailboxFolderPermissionData\AllUsers.csv" -NoTypeInformation
I have actually found a trick, it's not that clean but I got my report which is important :)

$allfolders = @()

$DB1 = Get-Mailbox -Identity "myMailbox"

ForEach ($Alias in $DB1)
{
$Mailbox = "" + $Alias.DisplayName
Write-Output $Mailbox
$res = get-recipient $mailbox | select Department,City
$mbdisp = @{Expression={$Alias.DisplayName};Label="DisplayName"}
$mbalias = @{Expression={$Alias.alias};Label="Alias"}
$mbdept = @{Expression={$res.department};Label="Department"}
$mbcity = @{Expression={$res.city};Label="City"}
$Folders = Get-MailboxFolderStatistics $Mailbox | % {$_.folderpath} | % {$_.replace(“/”,”\”)}

ForEach ($F in $Folders)
{
$FolderKey = $Mailbox + ":" + $F
$Permissions = Get-MailboxFolderPermission -identity $FolderKey -ErrorAction SilentlyContinue
$add = $Permissions | Where-Object {$_.User -notlike "Default" -and $_.User -notlike "Anonymous" -and $_.AccessRights -notlike "None" -and $_.AccessRights -notlike "Owner" -and $_.User -NotMatch "NT"}| Select $mbdisp,$mbalias,$mbdept,$mbcity,@{Expression={$_.User};Label="DelegateUser"},FolderName,@{Expression={$_.AccessRights};Label="AccessRights"}

$allfolders += $add
}
}

$allfolders | Where-Object {$_} | Export-Csv "D:\MailboxFolderPermissionData\AllUsers.csv" -NoTypeInformation
$importusers = import-csv "D:\MailboxFolderPermissionData\allusers.csv"

$outfile = "OwnerMailbox |Alias|Department|Location |DelagateUser |DelagateAlias |Department |DelegateLocation|FolderName|AccessRights"
$outfile > D:\MailboxFolderPermissionData\Final.csv
foreach ($user in $importusers)
{
$result = get-recipient $user.Delegateuser | select Displayname,Alias,Department,City

$outfile = $user.DisplayName + "|"+      $user.Alias       + "|"+ $user.Department +"|"+ $user.City +"|"+ $result.Displayname +"|"+ $result.Alias +"|"+ $result.Department  +"|"+ $result.City +"|"+ $user.FolderName + "|" + $user.AccessRights
$outfile >> D:\MailboxFolderPermissionData\Final.csv
}
 
#Formatting
$finalcsv = import-csv D:\MailboxFolderPermissionData\Final.csv -Delimiter '|'
$finalcsv | export-csv D:\MailboxFolderPermissionData\MbxFdrPermRprt.csv -NoTypeInformation


###########Send Mail########
$date = Get-date -Format dd/MM/yyyy
$fromaddress = "toto"
$toaddress = "admin"
$Subject = "Mailbox Folder Permission Report as of $date"
$attachment = "D:\MailboxFolderPermissionData\MbxFdrPermRprt.csv"
$smtpserver = "myserver"
 
####################################
 
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.CC.Add($CCaddress)
#$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$attach = new-object Net.Mail.Attachment($attachment)
$message.Attachments.Add($attach)
#$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
#####################################
Exit
################################################################################

Author

Commented:
got the report needed

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial