Script to change/add permissions on calendars using powershell

We have several calendars that I need to change permissions on. OVer the years we've added and removed folks and now its just a mess.

If possible what I would like to do is reset the permissions for all the calendars so that default is author. Then I have about 3 people that need owner access to all of the calender's.

is this possible with powershell?
LVL 2
msidnamAsked:
Who is Participating?
 
FOXActive Directory/Exchange EngineerCommented:
Msidnam,
Sorry about the delay.  I had to tweak this script and just tested.  Run each line individually

$cal=$_.emailaddresses+':\Calendar'
Import-CSV 'c:\temp\calrights.csv' | %{Set-mailboxfolderPermission $cal -User Default -AccessRights Author}
0
 
Alex Green3rd Line Server SupportCommented:
<# 
 
 NAME: Set-CalendarPermissions.ps1 
 
 AUTHOR: Jan Egil Ring 
 EMAIL: jan.egil.ring@powershell.no 
 
 COMMENT: Script to set calendar-permission for mailboxes in Exchange Server 2010. 
          For a list of valid AccessRights, see http://technet.microsoft.com/en-us/library/ff522363.aspx 
          More information: http://blog.powershell.no/2010/09/20/managing-calendar-permissions-in-exchange-server-2010 
 
 You have a royalty-free right to use, modify, reproduce, and 
 distribute this script file in any way you find useful, provided that 
 you agree that the creator, owner above has no warranty, obligations, 
 or liability for such use. 
 
 VERSION HISTORY: 
 1.0 19.09.2010 - Initial release 
 
#> 
 
#requires -version 2 
 
#Load Exchange Server 2010 Management Shell if not loaded. You may delete/comment out this step if you are running the script from the Exchange Management Shell 
if (-not (Get-PSSnapin | Where-Object {$_.Name -like "Microsoft.Exchange.Management.PowerShell.E2010"})){ 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
 
#Custom variables 
$mailboxes = Get-Mailbox -Database "Mailbox Database A" 
$AccessRights = "Reviewer" 
 
#Loop through all mailboxes 
foreach ($mailbox in $mailboxes) { 
 
#Retrieve name of the user`s calendar 
$calendar = (($mailbox.SamAccountName)+ ":\" + (Get-MailboxFolderStatistics -Identity $mailbox.SamAccountName -FolderScope Calendar | Select-Object -First 1).Name) 
 
#Check if calendar-permission for user "Default" is set to the default permission of "AvailabilityOnly" 
    if (((Get-MailboxFolderPermission $calendar  | Where-Object {$_.User -like "Default"}).AccessRights) -like "AvailabilityOnly" ) { 
 
    Write-Host "Updating calendar permission for $mailbox..." -ForegroundColor Yellow 
 
    #Set calendar-permission for user "Default" to value defined in variable $AccessRights 
    Set-MailboxFolderPermission -User "Default" -AccessRights $AccessRights -Identity $calendar 
    } 
}

Open in new window


https://gallery.technet.microsoft.com/ScriptCenter/19b98a56-42aa-4695-b07c-335d8322b64e/

I'm pretty sure this is what you're looking for.
0
 
Alex Green3rd Line Server SupportCommented:
And you stated all calendars, not just the ones you've got at the moment.

If it's just those ones.

$mailboxes = Get-Mailbox -Database "Mailbox Database A"

Modify that to

$mailboxes = Get-content c:\temp\mailboxnames.csv
0
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
msidnamAuthor Commented:
In my haste i forgot to mention that we are on exchange online so i am not sure how to tell what database we are on.
0
 
FOXActive Directory/Exchange EngineerCommented:
Alex- the script you put up is will set the 'Default' user to have Reviewer rights.  

msidnam
The below will give you your desired results.  Copy and paste below in to notepad and save it (calpermssions.txt).  Rename the .txt extenstion to .ps1
Open powershell and cd to wherever you saved the .ps1 file.   Once you are at the correct directory you will type    .\calpermissions.ps1
and press enter
The script will connect you to O365 prompting you for your credentials and then set your user mailbox calendar -user default permissions to Author.   For the other users that need owner rights in the script below substitute Default with the email address of the user that needs ownership and change Author below to Owner

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
foreach($user in Get-Mailbox -RecipientTypeDetails UserMailbox) {

$cal = $user.alias+":\Calendar"

Set-MailboxFolderPermission -Identity $cal -User Default -AccessRights Author

}
0
 
msidnamAuthor Commented:
Fox,
If i wanted to import a csv file with the calendar aliases could I do that as well? I remember seeing an imprt csv command. would i just add that to a variable and then use that instead of the Get-Mailbox command?
0
 
FOXActive Directory/Exchange EngineerCommented:
Create a .csv with a header named emailaddresses, underneath that header list all the emailaddresses in question where we will be setting the calendar rights.  Name it calrights.csv and put it where you please, example c:\temp\calrights.csv

script below:
Import-CSV 'c:\temp\calrights.csv' | %{Set-mailboxfolderPermission '$_.emailaddresses:\calendar' -User Default -AccessRights Author}

now for the owner:
Import-CSV 'c:\temp\calrights.csv' | %{Set-mailboxfolderPermission '$_.emailaddresses:\calendar' -User emailaddressofintendedowner -AccessRights Owner}
0
 
msidnamAuthor Commented:
It's telling me that the specified mailbox $_.emailaddresses doesn't exists
0
 
FOXActive Directory/Exchange EngineerCommented:
did you make your .csv file with the header of emailaddresses and list all the emailaddresses underneath?  send me a screenshot of the .csv file either in notepad or excel
0
 
msidnamAuthor Commented:
I only have one entered as i wanted to test with a calendar that isn't used much just in case.

Is it case sensitive?
emailaddresses.PNG
0
 
FOXActive Directory/Exchange EngineerCommented:
then check the user's calendar rights

Get-MailboxFolderPermission bobcasouth@domain.com:\calendar | ft -auto
0
 
msidnamAuthor Commented:
sorry. now it's saying it isnt a mailbox user. which i guess is technically correct since its a room mailbox.
0
 
FOXActive Directory/Exchange EngineerCommented:
1. The command I fixed gave it the author permission correct?

Which command threw the error?  You have to be specific
0
 
msidnamAuthor Commented:
correct, the author permission. when i run the script is says it isnt a mailbox. it gives a long servername.
0
 
FOXActive Directory/Exchange EngineerCommented:
Please send a screenshot of the command with error thrown.
0
 
msidnamAuthor Commented:
below is the error. I X out some of the items that might be sensitive to us.


The specified mailbox "NAMPRXXXX.PROD.OUTLOOK.COM/Microsoft Exchange Hosted
Organizations/companydomain.onmicrosoft.com/officeadmin" doesn't exist. Reason: NAMPRXXXX.PROD.OUTLOOK.COM/Microsoft
Exchange Hosted Organizations/companydomain.onmicrosoft.com/officeadmin isn't a mailbox user.
    + CategoryInfo          : NotSpecified: (:) [Set-MailboxFolderPermission], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=DM3PR13MB0506,RequestId=119d66ac-724d-4717-b8a9-a7164d95eaea,TimeStamp=12/13/201
   7 10:13:10 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] E8659C98,Microsoft.Exchange.Management.S
  toreTasks.SetMailboxFolderPermission
    + PSComputerName        : outlook.office365.com


if I run the command just using:
Set-MailboxFolderPermission bocasouth@mycompany.com:\calendar -user default -AccessRights author it runs. I'm not sure where i am messing up with the variable. ive edited it in notepad++ to ensure the file is saved correctly.
0
 
FOXActive Directory/Exchange EngineerCommented:
Copy, paste and run this line first
$cal=$_.emailaddresses+':\Calendar'

then copy, past and run this line afterwards
Import-CSV 'c:\temp\calrights.csv' | %{Set-mailboxfolderPermission $cal -User Default -AccessRights Author}
0
 
FOXActive Directory/Exchange EngineerCommented:
Have you set the correct filepath if your .csv if it  is not sitting in c:\temp?
0
 
msidnamAuthor Commented:
I get the same error. Do i need to give the import csv a variable?

the only thing i am changing from your script is the path to my csv file.
0
 
FOXActive Directory/Exchange EngineerCommented:
No.  I ran the command and it works flawlessly.  Something you are doing is wrong.  That error you sent me says officeadmin doesn't even exist.  The mailbox that you have listed in your spreadsheet is it sitting on O365?  Check your spreadsheet and the mailbox that is in it, verify the emailaddress is correct.

You have bocasouth@mycompany.com when you run it manually

but the error is looking for officeadmin?
0
 
msidnamAuthor Commented:
yes. i was confused by that as well. officeadmin is the user i logged in as with the script above to get the session (which does not have any mailbox), but the room i want to manipulate is bocasouth@mycompany.com

I'm about o head home but i will log in from home and continue on this. I might just reboot my computer im using to do the scripting, relog on to O365 with the script above and start fresh.
0
 
FOXActive Directory/Exchange EngineerCommented:
you must make a connection via powershell to exchange online(o365) with your O365 admin credentials
0
 
msidnamAuthor Commented:
I was able to make the connection with PowerShell and I am able to run the command. But I'm not sure what I am doing wrong.

I ran a similar script to the one you gave me that added users to a DL and that worked.

I'm going to see if I can find that script and compare.
0
 
msidnamAuthor Commented:
It works on my local exchange server but not on O365. Something must not be right but i am not sure what. Thank you for the help. I will need to see what the difference is but i know your script works.
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.