# Add Calender and Full Mailbox permission
# By Alberto Igbinedion

# Import Uusers list
$users = Import-Csv C:\Scripts\Input\CalanderPermission.csv 



foreach ($User in $Users) {

# Add Calendar Permission

Add-MailboxFolderPermission "$($user.manager.Trim()):\calendar" -User ($user.pa.Trim() + "@ons.gov.uk") –AccessRights Editor
Set-MailboxFolderPermission "$($user.manager.Trim()):\calendar" -User ($user.pa.Trim() + "@ons.gov.uk") –AccessRights Editor

# Remove Mailbox Permission
#Remove-MailboxPermission -Identity $user.manager.Trim() -User $user.pa.Trim() -AccessRights FullAccess -InheritanceType all

# Add and set Mailbox Permission
Add-MailboxPermission -Identity $user.manager.Trim() -User $user.pa.Trim() -AccessRights FullAccess -InheritanceType all -AutoMapping:$True

Set-Mailbox -Identity $user.manager.Trim() -GrantSendOnBehalfTo @{add="$($user.pa.Trim())"}

# Add AD Send-As Permission
# Get-mailbox $user.manager.Trim() | Add-ADPermission  -User $user.pa.Trim() -AccessRights 'ExtendedRight' -ExtendedRights 'send as'

# Check Set Permission
Get-MailboxFolderPermission -Identity "$($user.manager):\calendar"
Get-MailboxPermission -Identity $user.manager.Trim()
# Get-Mailbox -Identity $user.manager.Trim() | Get-ADPermission | where {($_.ExtendedRights -like “*Send-As*”)}

}

#Editor, Owner

# Good To Go


<#

Add one or more values to a multivalued property   :  @{Add="<value1>", "<value2>", "<value3>"}

Remove one or more values from a multivalued property    : @{Remove="<value1>", "<value2>", "<value3>"}

#>