Forum Discussion
Salim_95
Jan 15, 2019Copper Contributor
Getting shared mailboxes with no delegates in Powershell
Hi, I'm quite new to powershell and am just wondering if there's a way to get all of the shared mailboxes in Office 365 that haven't got any delegates on them? Thanks Salim
Salim_95
Jan 16, 2019Copper Contributor
I'm referring to shared mailboxes that are just sitting there with nobody having access to them whatsoever. Just need to clear out shared mailboxes that aren't being used.
VasilMichev
Jan 17, 2019MVP
Hm, for this scenario perhaps a better way will be to do a message trace instead? I mean you might have shared mailboxes that nobody can access (no permissions granted), however they might still be receiving messages, isn't thing something you want to account for?
- Salim_95Jan 17, 2019Copper ContributorHi Vasil,
Yeah definitely but I don't think a message trace would be the way to go. I'm not looking to delete them before checking with the site users and that's why I'd like to see a list of shared mailboxes that are just sitting there in 365 that nobody has been delegated access to. I doubt it'd be a large number but we have too many shared mailboxes for me to go through all of them one by one.- VasilMichevJan 19, 2019MVP
Well, here's a quick sample of what you can do with PowerShell:
Get-Mailbox -RecipientTypeDetails SharedMailbox |select PrimarySmtpAddress,@{n="FullAccess";e={ (Get-MailboxPermission $_.PrimarySmtpAddress | ? {($_.User -ne "NT AUTHORITY\SELF") -and ($_.IsInherited -ne $true) -and ($_.AccessRights -match "FullAccess") -and -not ($_.User -like "S-1-5*")}).User -join "," }} |? {!$_.FullAccess}It's a one-liner, so a bit ugly, but should get the job done. Do note that it will take a long time to run if you have a large number of mailboxes. Also it doesn't cover any folder-level permissions, if you want these included best go with a full-blown script. I have few samples posted on the TechNet Gallery, you can easily adapt them.
- azchriskingMar 27, 2020Copper Contributor
Excellent, thanks for sharing! VasilMichev