export shared mailbox permission

Steel Contributor

hi,

 

i have script below to export permission of shared mailbox.

issue is that the exported csv file exported 1 shared mailbox only.

 

______________________________________________________

 

Import-Module ExchangeOnlineManagement

Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $truE

$mailboxes=Get-Mailbox -ResultSize unlimited -RecipientTypeDetails SharedMailbox

foreach($mailbox in $mailboxes){

Get-MailboxPermission $mailbox.name | select Identity,User,AccessRights | Export-Csv C:\Users\contoso\Desktop\sharedmailbox.csv –NoTypeInformation

}

Write-Host "DONE RUNNING SCRIPT"

 

__________________________________________________________________

 

 

1 Reply

You are effectively overwriting the CSV file on each iteration, use the -Append switch:

 

Export-Csv C:\Users\contoso\Desktop\sharedmailbox.csv –NoTypeInformation -Append

 

I would also suggest to use a proper identifier for the mailbox, as Name might not be unique. Something like $mailbox.UserPrincipalName should work better.