PowerShell: Update User Permissions for a Shared Mailbox or Calendar using Add-MailboxFolderPermission

 I use this simple script to update permissions for a Shared Calendar for a group of Users.  This can be used for updating permissions to other Shared Mailbox Folders also.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName alex.g@COMPANY.com

#Create a list of User email addressses by seraching specific OUs and adding them to a users variable.
$users = get-aduser -filter * -SearchBase "OU=MEC_Operations,OU=MEC,OU=COMPANY Users,DC=COMPANY,DC=local" -Properties mail | Select-Object mail
$users += get-aduser -filter * -SearchBase "OU=COL_Operations,OU=COL,OU=COMPANY Users,DC=COMPANY,DC=local" -Properties mail | Select-Object mail
$users += get-aduser -filter * -SearchBase "OU=HAR_Operations,OU=HAR,OU=COMPANY Users,DC=COMPANY,DC=local" -Properties mail | Select-Object mail
$users += get-aduser -filter * -SearchBase "OU=RIC_Operations,OU=RIC,OU=COMPANY Users,DC=COMPANY,DC=local" -Properties mail | Select-Object mail
$users += get-aduser -filter * -SearchBase "OU=MEC_Terminal_Support,OU=MEC,OU=COMPANY Users,DC=COMPANY,DC=local" -Properties mail | Select-Object mail

#export this list to a CSV File to check for accuracy. 
$users | Export-Csv -Path C:\Users\alexg\Desktop\AccountingUsers.csv

#Prompts the user to continue the script after checking for accuracy
Read-Host -Prompt "Press Enter to continue"

#Imports the CSV file
$UsersCSV = Import-Csv -Path C:\Users\alexg\Desktop\AccountingUsers.csv

#Loops throught the CSV and sets mailbox permissions for that user.
foreach ($row in $UsersCSV) 
{
    add-mailboxfolderpermission OpsTimeOffCal@COMPANY.com:\calendar -user $row.mail  -accessrights Reviewer -SendNotificationToUser $true 
}

Comments

Popular posts from this blog

A script to check a log file. If conditions are met the script will then delete, and copy in a file into the folder.

Laptop Battery Replacement

Bulk AD User creation Powershell Script