export shared mailbox permission

%3CLINGO-SUB%20id%3D%22lingo-sub-2141383%22%20slang%3D%22en-US%22%3Eexport%20shared%20mailbox%20permission%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2141383%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ei%20have%20script%20below%20to%20export%20permission%20of%20shared%20mailbox.%3C%2FP%3E%3CP%3Eissue%20is%20that%20the%20exported%20csv%20file%20exported%201%20shared%20mailbox%20only.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E______________________________________________________%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImport-Module%20ExchangeOnlineManagement%3C%2FP%3E%3CP%3EConnect-ExchangeOnline%20-Credential%20%24UserCredential%20-ShowProgress%20%24truE%3C%2FP%3E%3CP%3E%24mailboxes%3DGet-Mailbox%20-ResultSize%20unlimited%20-RecipientTypeDetails%20SharedMailbox%3C%2FP%3E%3CP%3Eforeach(%24mailbox%20in%20%24mailboxes)%7B%3C%2FP%3E%3CP%3EGet-MailboxPermission%20%24mailbox.name%20%7C%20select%20Identity%2CUser%2CAccessRights%20%7C%20Export-Csv%20C%3A%5CUsers%5Ccontoso%5CDesktop%5Csharedmailbox.csv%20%E2%80%93NoTypeInformation%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3EWrite-Host%20%22DONE%20RUNNING%20SCRIPT%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E__________________________________________________________________%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2141383%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2142070%22%20slang%3D%22en-US%22%3ERe%3A%20export%20shared%20mailbox%20permission%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2142070%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20are%20effectively%20overwriting%20the%20CSV%20file%20on%20each%20iteration%2C%20use%20the%20-Append%20switch%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EExport-Csv%20C%3A%5CUsers%5Ccontoso%5CDesktop%5Csharedmailbox.csv%20%E2%80%93NoTypeInformation%20-Append%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EI%20would%20also%20suggest%20to%20use%20a%20proper%20identifier%20for%20the%20mailbox%2C%20as%20Name%20might%20not%20be%20unique.%20Something%20like%20%24mailbox.UserPrincipalName%20should%20work%20better.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Super 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.