Script Name: Set-InternalExternalURLs.ps1
Script Author: Ståle Hansen
Log:
- v01 07.07.2010
- Initial Script. Finds calendar folder for all users, checks if it is in Norwegian or English, adds permissions for callendar sharing
- Added option for some users to gain full access of spesific users calendars
- Added Option to set editor access on individual mailboxes
- Added option to set review for users created last 30 days
- V02 30.09.2011
- Updated and verified the script to work both in Exchange Server 2010 and Exchange Online
#################################################################################################### # Set-CalendarPremissions.ps1 # # v02 September2011 by MVP Ståle Hansen (http://msunified.net) # #################################################################################################### [System.Console]::ForegroundColor = [System.ConsoleColor]::White clear-host write-host write-host Script for setting calendar folder for all users to default reviewer write-host this is good for organizations using shared calendars write-host write-host Please choose an option below: write-host write-host '1) All users' write-host '2) All users created last 30 days' write-host '3) Give indivdual users full access to individual users calendars' write-host '4) Exit' -ForegroundColor Red write-host $opt = Read-Host "Select an option [1-4]" switch ($opt) { 1{ #Set default as reviewer for all calendars. #Will check if the user has english or norwegian language on their calendar folder foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch "discovery"}) { $mbox = $mbx.alias+":\calendar" $test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue if($test -ne $null){ Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null [string]$user=$mbx.name [string]$folder="Calendar" [string]$AccessRight="Applied" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } else{ $mbox = $mbx.alias+":\kalender" Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null [string]$user=$mbx.name [string]$folder="Kalender" [string]$AccessRight="Applied" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } } [System.Console]::ForegroundColor = [System.ConsoleColor]::Gray } 2{ #Set default as reviewer for all calendars. #Will check if the user has english or norwegian language on their calendar folder #Will only apply for users created last 30 days foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch "discovery"} | Get-MailboxStatistics | where-object {$_.LastLogonTime -lt (get-date).adddays(-30)} | Get-Mailbox) { $mbox = $mbx.alias+":\calendar" $test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue if($test -ne $null){ Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null [string]$user=$mbx.name [string]$folder="Calendar" [string]$AccessRight="Applied" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } else{ $mbox = $mbx.alias+":\kalender" Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null [string]$user=$mbx.name [string]$folder="Kalender" [string]$AccessRight="Applied" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } } [System.Console]::ForegroundColor = [System.ConsoleColor]::Gray } 3{ #Will give inputted user access to inputted calendar folder Editor accessright #Typically for Servicedesk users Write-Host "Please type the alias of the user you want to set the permission on: " -nonewline $mbx = Read-Host Write-Host "Please type the alias of the user you want to give editor access on $mbx's calendar folder: " -nonewline $editor = Read-Host $mbox = $mbx+":\calendar" $test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue if($test -ne $null){ Set-MailboxFolderPermission -Identity $mbox -User $editor -AccessRights Editor | out-null [string]$user=$mbx [string]$folder="Calendar" [string]$AccessRight="Editor" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } else{ $mbox = $mbx+":\kalender" Set-MailboxFolderPermission -Identity $mbox -User $editor -AccessRights Editor | out-null [string]$user=$mbx [string]$folder="Kalender" [string]$AccessRight="Editor" $obj = New-Object PSObject $obj | Add-Member NoteProperty User ($user) $obj | Add-Member NoteProperty Folder ($folder) $obj | Add-Member NoteProperty AccessRight ($AccessRight) Write-Output $obj } [System.Console]::ForegroundColor = [System.ConsoleColor]::Gray } 4{ [System.Console]::ForegroundColor = [System.ConsoleColor]::Gray } }
[…] Get the script here: https://msunified.net/exchange-downloads/script-set-calendarpermissions-ps1/ […]
Can the script be modified to grant one group editor rights to all calendars? At work we want the Secretary group to be able to edit all calendars. I’m not a powershell pro by far so i want to know if this is a quick add-on to the script.
Thanks for this script. I kept getting errors with the “Set-MailboxFolderPermission” command. I had to change it to “Add-Mai;boxFolderPermission”. The error stated “No existing permission entry found for user..”
———-
To Heintraag, here is how I modified the script to add reviewer access for a particular user on all calendars. I jsut did this and haven’t fully tested. I am also not a powershell pro so I hope it works. I think I can probably remove the $test section for my purposes since I don’t have any other languages in my environment.
———–
Write-Host “Please type the alias of the user to whom you want to grant reviewer access on all calendar folders: ” -nonewline
$reviewer = Read-Host
foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch “discovery”}) {
$mbox = $mbx.alias+”:\calendar”
$test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue
if($test -ne $null){
Add-MailboxFolderPermission -Identity $mbox -User $reviewer -AccessRights Reviewer | out-null
[string]$user=$mbx
[string]$folder=”Calendar”
[string]$AccessRight=”Reviewer”
$obj = New-Object PSObject
$obj | Add-Member NoteProperty User ($user)
$obj | Add-Member NoteProperty Folder ($folder)
$obj | Add-Member NoteProperty AccessRight ($AccessRight)
Write-Output $obj
}
}
————-
FYI the title of this page is set as “SCRIPT: Set-CalendarPremissions.ps1” permissions is spelled wrong. I had copied it to save the script locally and was scratching my head when it kept giving errors when I typed it with correct spelling. Thanks for sharing the script, it worked great for me! Cheers!
yeah, I know, its one of those caveats :)
Do you know how to make this script work when we got multiple users with two mailboxes?
The alias is the same so I get the “The specified mailbox ******* isn’t unique” when running the script.
Maybe make it look at the UserPrincipalName instead of alias?
Have a look at this. http://anewmessagehasarrived.blogspot.com/2012/03/update-calendar-folder-permission.html
I have changed the script so it determines the Calendar folder name which is useful in a Multilanguage user environment.
####################################################################################################
# Set-CalendarPremissions.ps1
#
# v02 September2011 by MVP Ståle Hansen (http://msunified.net)
# Modified by M de Groot januari 2014
#
####################################################################################################
[System.Console]::ForegroundColor = [System.ConsoleColor]::White
clear-host
write-host
write-host Script for setting calendar folder for all users to default reviewer
write-host this is good for organizations using shared calendars
write-host
write-host Please choose an option below:
write-host
write-host ‘1) All users’
write-host ‘2) All users created last 30 days’
write-host ‘3) Give indivdual users full access to individual users calendars’
write-host ‘4) Exit’ -ForegroundColor Red
write-host
$opt = Read-Host “Select an option [1-4]”
switch ($opt) {
1{
#Set default as reviewer for all calendars.
foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch “discovery”}) {
$cfolder = Get-MailboxFolderStatistics -Identity $mbx.alias -FolderScope Calendar | Select-Object -First 1 Name
$mbox = $mbx.alias+”:\”+$cfolder.name
Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer -WarningAction SilentlyContinue *>&1 | out-null
# For adding rights for the Calendar administrator (or secretary)
# Add-MailboxFolderPermission -Identity $mbox -User Michel -AccessRights Editor -WarningAction SilentlyContinue *>&1 | out-null
[string]$user=$mbx.name
[string]$folder=$cfolder.name
[string]$AccessRight=”Applied”
$obj = New-Object PSObject
$obj | Add-Member NoteProperty User ($user)
$obj | Add-Member NoteProperty Folder ($folder)
$obj | Add-Member NoteProperty AccessRight ($AccessRight)
Write-Output $obj
}
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
}
2{
#Set default as reviewer for all calendars.
#Will only apply for users created last 30 days
foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch “discovery”} | Get-MailboxStatistics | where-object {$_.LastLogonTime -lt (get-date).adddays(-30)} | Get-Mailbox) {
$cfolder = Get-MailboxFolderStatistics -Identity $mbx.alias -FolderScope Calendar | Select-Object -First 1 Name
$mbox = $mbx.alias+”:\”+$cfolder.name
Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer -WarningAction SilentlyContinue *>&1 | out-null
# For adding rights for the Calendar administrator (or secretary)
# Add-MailboxFolderPermission -Identity $mbox -User Michel -AccessRights Editor -WarningAction SilentlyContinue *>&1 | out-null
[string]$user=$mbx.name
[string]$folder=$cfolder.name
[string]$AccessRight=”Applied”
$obj = New-Object PSObject
$obj | Add-Member NoteProperty User ($user)
$obj | Add-Member NoteProperty Folder ($folder)
$obj | Add-Member NoteProperty AccessRight ($AccessRight)
Write-Output $obj
}
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
}
3{
#Will give inputted user access to inputted calendar folder Editor accessright
#Typically for Servicedesk users
Write-Host “Please type the alias of the user you want to set the permission on: ” -nonewline
$mbx = Read-Host
Write-Host “Please type the alias of the user you want to give editor access on $mbx’s calendar folder: ” -nonewline
$editor = Read-Host
$cfolder = Get-MailboxFolderStatistics -Identity $mbx.alias -FolderScope Calendar | Select-Object -First 1 Name
$mbox = $mbx+”:\”+$cfolder
Set-MailboxFolderPermission -Identity $mbox -User $editor -AccessRights Editor -WarningAction SilentlyContinue *>&1 | out-null
[string]$user=$mbx
[string]$folder=”Calendar”
[string]$AccessRight=”Editor”
$obj = New-Object PSObject
$obj | Add-Member NoteProperty User ($user)
$obj | Add-Member NoteProperty Folder ($folder)
$obj | Add-Member NoteProperty AccessRight ($AccessRight)
Write-Output $obj
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
}
4{
[System.Console]::ForegroundColor = [System.ConsoleColor]::Gray
}
}
Awesome! Thanks for sharing :)
I am a true beginner! I am looking for help on a script.
I would like to have the script ask the user to enter the Owners email, then run the Get-Mailbox command. Then do an if/then statement to add users permissions.
I kind of need a jumping off point to get started. Any help would be appreciated. Even recommended books would be great. Trying this on my own… schools way to expensive !
I am trying to combine steps into one script:
$Mbox = “Owners.email”
Get-MailboxFolderPermission $Mbox”:\Calendar”
If user does not have permissions to the calendar
$User = “USERs.email”
Add-MailboxFolderPermission $Mbox”:\Calendar” -User “$User” -AccessRights PublishingEditor
If user already has permissions but you need to change them
Set-MailboxFolderPermission $Mbox”:\Calendar” -User “$User” -AccessRights PublishingEditor
I recommend reading this blogpost by my colleague Alexander Holmeset about how he got in to automation with some recommendations as well https://alexholmeset.blog/2018/01/01/my-story-on-how-i-got-into-automation-and-why-you-should-do-the-same-in-2018/