Get MailboxFolderPermission script to CSV - Exchange 2010

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!!
LVL 2
Jaime UmaliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manikandan NarayanswamySecurity Specialist & IBM Security GuardiumCommented:
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
Jaime UmaliAuthor 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
Jaime UmaliAuthor Commented:
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
################################################################################

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jaime UmaliAuthor Commented:
got the report needed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.