Set calendar permissions using Attributes in Exchange 2010 Powershell

Hi

I have recently set all the attributes for our company within AD, and want to set the calendar permissions for all users within one department to be able to access each others calendars.

eg.

If Department Attribute = "HR"
          set calendar permissions for HR group to Full

Any help is appreciated

M@
LVL 12
mattclarifiedAsked:
Who is Participating?
 
soostibiConnect With a Mentor Commented:
Could you ensure that the line breakes are in place, you run the code as it is in my comment?
I run it in my test environment without any problem. Here is another version, which updates the permission if HR is already have a different version on the calendar.
$group = ("yourdomain\HR" | Get-Recipient | Select-Object -ExpandProperty primarysmtpaddress).tostring()
  
$mbxs = Get-User -RecipientTypeDetails usermailbox -Filter {department -eq "HR"} | Get-Mailbox   
  
$mbxs | %{  
    $folder = $_ | Get-MailboxFolderStatistics  -FolderScope calendar | Select-Object -ExpandProperty name
    if(get-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\$folder" -user $group -erroraction silentlycontinue){
        Set-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\$folder" -AccessRights owner -User $group 
    }
    else{
        Add-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\$folder" -AccessRights owner -User $group 
    }
}

Open in new window

0
 
soostibiCommented:
Try this, customize the value of $group in first line.
$group = "yourdomain\HR"

$mbxs = Get-User -RecipientTypeDetails usermailbox | ?{$_.department -eq "HR"}| Get-Mailbox 

$mbxs | %{
    $smtp = $_.primarysmtpaddress.tostring() 
    $folder = $_ | Get-MailboxFolderStatistics  -FolderScope calendar | Select-Object -ExpandProperty name 
    Add-MailboxFolderPermission -Identity "$($smtp):\$folder" -AccessRights owner -User $group
}

Open in new window

0
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
I can't test this, at all, not at work, and not running Exchange 2010. But something along these lines should work.
Get-User -Filter { Department -eq 'HR' } -RecipientType UserMailBox | ForEach-Object {
  Add-MailboxFolderPermission "$($_.PrimarySmtpAddress):\Calendar" -User "HR Group" -AccessRights Owner
}

Open in new window

Owner is as high as they go, if you don't want it quite that high perhaps pick on Editor or Author.

Chris
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
soostibiCommented:
A bit more optimised solution is below. The main difference between Chris' solution and mine, is that my works also in an international environment, where the folder Calendar has name in a different language.
$group = "yourdomain\HR"  

$mbxs = Get-User -RecipientTypeDetails usermailbox -Filter {department -eq "HR"} | Get-Mailbox 

$mbxs | %{
    $folder = $_ | Get-MailboxFolderStatistics  -FolderScope calendar | Select-Object -ExpandProperty name 
    Add-MailboxFolderPermission -Identity "$($_.PrimarySMTPAddress):\$folder" -AccessRights owner -User $group}

Open in new window

0
 
mattclarifiedAuthor Commented:
Thanks for your input both, I have run the following which seems to change the permissions on my calendar but not on any others in the group

get-user -filter { Department -eq "Department" } -RecipientType UserMailbox | ForEach-Object {
Set-MailboxFolderPermission "$($_.PrimarySmtpAddress):\Calendar" -User manager@company.com -AccessRights Reviewer }

I am testing it with one user getting access first before I start using groups, any ideas?

Thanks
M@
0
 
Chris DentPowerShell DeveloperCommented:
Is this returning the right number of users?

get-user -filter { Department -eq "Department" } -RecipientType UserMailbox

I think you'll want Add- instead of Set- for the permission as well. I think Set- will only modify the right if it's already there.

Chris
0
 
mattclarifiedAuthor Commented:
Thanks Chris, running the above command lists all the users within the specific Department.   I tried using add and it says that the permission already exists, it still seems to me that its trying to set it on my own account over and over.

M@
0
 
mattclarifiedAuthor Commented:
soos, when i try to run your version it returns

A parameter cannot be found that matches parameter name 'Identity'.

M@
0
 
mattclarifiedAuthor Commented:
Thanks soos, took it exactly as you had written it there, think it may have been because i was chopping your expert work up, should of listened to you in the first place!
Some points for Chris too for helping

Thanks for your help!

M@
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.