A customer want two specifik users to have edit permissions on certain users in the company. It’s many users, is a situation that might have to be done again and again.
So we use powershell for the solution.
First we created a script to check the current permissions to get a baseline of what we’re working with.
foreach ($user in get-content editcalendarusers.txt)
{
write-host "Permissions for user: $user" -foregroundcolor red -backgroundcolor yellow
get-mailboxfolderpermission ${user}:\calendar
}
Where editcalendarusers.txt is a text with one username per line. This is also a good way of validating your editcalenderusers.txt list, to catch any errors or localized boxes.
Since set-mailboxfolderpermissions only can edit existing userpermissions, not add new ones, we first need to run add-mailboxfolderpermission on our userlist. If an account already exist ps throws an error, but no changes are made. Other users already added to the permssions aren’t modified.
First script
----addperm.ps1----
foreach ($user in get-content editcalendarusers.txt)
{
add-mailboxfolderpermission ${user}:\calendar -user john.doe -Accessrights Editor
write-host "john.doe added as editor for $user."
add-mailboxfolderpermission ${user}:\calendar -user charles.doe -Accessrights Editor
write-host "charles.doe added as editor for $user."
}
-----eof-----
Second script
----setperm.ps1.
foreach ($user in get-content editcalendarusers.txt)
{
set-mailboxfolderpermission ${user}:\calendar -user john.doe -Accessrights Editor
write-host "john.doe added as editor for $user."
set-mailboxfolderpermission ${user}:\calendar -user charles.doe -Accessrights Editor
write-host "charles.doe added as editor for $user."
}---eof-----
If the permissions already are set the second script reports this and goes on to the next line.
One error we ran into was that a few users had changed the language on their mailbox. On these we exchanged the :\calender for the correct folder. In our case :\kalender .
Now obviously we could have made this less static by adding a second loop to process the editors but in this case there were only two so it wasn’t really necessary in this case.
References:
http://technet.microsoft.com/en-us/library/dd298062%28v=exchg.150%29.aspx
No comments:
Post a Comment