I need some help with my script that I've come up with that I'm having some trouble getting it to work without giving an error or warning message.
So far I have this logic that gives "reviewer" permission to everyone's calendar individually to a specific mail-enabled AD security group:
$users = Get-Mailbox | Select -ExpandProperty Alias;
Foreach ($user in $users) {Add-MailboxFolderPermission $user":\Calendar" -user *GROUP1* -accessrights Reviewer};
This works fine, but we create and remove user accounts often so I need the script to run as economically as possible. This logic above will check and error on each user that already has a permission set, which can take a while and adds a lot to the error logs.
What I would like is an IF
statement, or revision to the Select property
in the script that can check if a user has currently no permissions set to the security group, then add the permission, so if they have the permission set already it will just skip.
Something like this:
$users = Get-Mailbox | Select -ExpandProperty Alias;
$users2 = Get-MailboxFolderPermission -Identity $users:\Calendar -User *GROUP1* IF accessrights = NULL** ???;
Foreach ($user in **$users2**) {Add-MailboxFolderPermission $user":\Calendar" -user *GROUP1* -accessrights Reviewer};