Forum Discussion
fstorer
Apr 18, 2024Brass Contributor
Get a report showing specific shared mailboxes and Display Names of their members on one line.
Dear Community, I have been asked to generate an excel report showing all our shared mailboxes starting with "jobs-". For each shared mailbox we want to see the members' Display Names (not the emai...
- Apr 19, 2024Sorry, that's what happens when I write code directly in the browser 😄
For the sorting bit, this should do:
$membersString = ($memberNames | sort -Unique) -join ", "
fstorer
Apr 19, 2024Brass Contributor
Thank you VasilMichev for your reply. I tried the code, but it doesn't work. For each shared mailbox I get only one name and not the full list of members. Is there something else I am missing?
VasilMichev
Apr 19, 2024MVP
Ah, I forgot to append the value. Try with:
$jobs = Get-EXOMailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited -Filter { DisplayName -like 'jobs-*' }
$JobsReport = @()
foreach ($job in $jobs) {
$Members = Get-MailboxPermission $job.identity | Where-Object { ($_.User -like '*@*') | Sort-Object User
foreach ($Member in $Members) {
$DisplayName += ((Get-User $Member.User).DisplayName)
}
$JobsReport += [PSCustomObject]@{
SharedMailbox = $job.Alias
MemberDN = $DisplayName -join ","
}
}
- fstorerApr 19, 2024Brass Contributor
VasilMichev, thank you for your time, unfortunately the script is not working...
Now I get the same names repeated N times for each mailbox without delimiter and not sorted.
- fstorerApr 19, 2024Brass Contributor
I was able to get what I wanted, although the Display Names are not sorted alphabetically. Thank you VasilMichev This is the code:
$jobs = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -Filter {DisplayName -like "jobs-*"} | Sort-Object DisplayName $JobsReport = @() foreach ($job in $jobs) { $members = Get-MailboxPermission -Identity $job.Identity | Where-Object { ($_.User -like '*@*') $memberNames = @() foreach ($member in $members) { $memberName = (Get-Mailbox $member.User).DisplayName $memberNames += $memberName } $membersString = $memberNames -join ", " $JobsReport += [PSCustomObject]@{ "Jobs Accounts" = $job.DisplayName "Members with Full Access" = $membersString } } $JobsReport = $JobsReport | Sort-Object "Jobs Accounts"
- VasilMichevApr 19, 2024MVPSorry, that's what happens when I write code directly in the browser 😄
For the sorting bit, this should do:
$membersString = ($memberNames | sort -Unique) -join ", "