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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 DentPowerShell 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
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
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

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
soostibiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.