Reputation: 81
I'm rather new to Powershell, but I am trying to get the Primary SMTP Address of all Shared Mailboxes in the domain in order to extract the privileges that users (and all users in groups) have on said Mailbox:
$permissions = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize unlimited | Get-ExoMailboxPermission | Select-Object Identity,User,AccessRights
$uniqueGroups = @{}
$groups = $permissions.User | where {$_ -notlike "NT AUTHORITY\SELF"} | where {$_ -notlike "*@*"}
$owners = $permissions | where {$_.User -notlike "NT AUTHORITY\SELF"} | where {$_.User -notlike "*@*"} | Select-Object Identity
foreach ($owner in $owners) {
$smpt = Get-ExoMailbox -Identity $owner | Select-Object PrimarySmtpAddress
echo $smpt
}
foreach ($group in $groups) {
if (-not $uniqueGroups.ContainsKey($group)) {
$uniqueGroups[$group] = $true
echo $group
$groupmembers = Get-DistributionGroupMember -Identity $group
echo $groupmembers
}
}
echo "Number of unique groups: $($uniqueGroups.Count)"
However, the Get-ExoMailbox -Identity $owner | Select-Object PrimarySmtpAddress
statement throws the Error that the Identity can't be found. When I execute the Get-ExoMailbox command directly in Powershell with any of the error-throwing Identities, it works without any problems. Any help would be very appreciated.
Upvotes: 0
Views: 132
Reputation: 81
Using $smpt = Get-ExoMailbox -Identity $owner.Identity | Select-Object PrimarySmtpAddress
works because the Select-Object statement before returns an Object instead of a String.
Upvotes: 0