Script with set-mailboxfolderpermission not working if alias is not unique RRS feed

  • Question

  • Hi,

    I have a script that runs each night adding a user to all mailboxes in a specific OU:

    $users = Get-Mailbox -Resultsize unlimited -OrganizationalUnit "OU=MyOU,DC=Domain,DC=local" | Select -ExpandProperty Alias
    Foreach ($user in $users) {
    Set-MailboxFolderPermission $user":\Calendar" -user SomeUser -accessrights Editor

    This works fine but now we have a few users with the same alias and therefore the script fails.

    I tried to change the "Get-mailbox" line to select either "PrimarySmtpAddress" or "WindowsEmailAddress" instead of "Alias" however this does not work eventhough it's the correct identity

    How do I change this so it will work on all users in the OU? Lets say I have a mailbox with identity "abc" twice though with the e-mail "" and "". If I run get-mailbox -identity abc it returns both mailboxes.


    • Edited by Jan Knudsen Wednesday, August 23, 2017 8:17 AM
    Wednesday, August 23, 2017 8:16 AM

All replies

  • Simply use something like this:

    $users = Get-Mailbox -Resultsize unlimited -OrganizationalUnit "OU=MyOU,DC=Domain,DC=local"
    $users.PrimarySmtpAddress | % {Set-MailboxFolderPermission ($_ + ":\Calendar") -User SomeUser -Accessrights Editor}

    Wednesday, August 23, 2017 7:43 PM