Monday, February 23, 2015

Add / Remove user in BookInPolicy / ResourceDelegate - Exchange 2013


Add / Remove user in BookInPolicy / ResourceDelegate - Exchange 2013 powershell

When we create a function of ResourceDelegate, below will be the effect:

#user gets added to calendar folder with access permissions as {Editor}
#user gets added to ResourceDelegates and not in BookInPolicy.

To add Calendar Resource Delegate we can use below function which creates a cmdlet ‘Add-CalendarResourceDelegate’ in powershell:

function Add-CalendarResourceDelegate {
Param(
$RoomName
, $newDelegate
)
$resourceDelegates = (Get-CalendarProcessing -Identity $RoomName).ResourceDelegates
$resourceDelegates += $newDelegate
Set-CalendarProcessing -Identity $RoomName -ResourceDelegates $resourceDelegates
}

CMD syntax:

Add-CalendarResourceDelegate -Identity $Roomname "MeetingRoom@Test.com" -newDelegate UserID9


To Remove All Users from ResourceDelegate:

Set-CalendarProcessing -Identity "MeetingRoom@Test.com" -ResourceDelegates $null

  
===========================================================

When we use function of Bookinpolicy below will be the effect:
#user gets added to bookinpolicy and current users will be retained.
#user gets added to calendar folder with access permissions as {LimitedDetails}

To add user in Calendar BookIn Policy we can use below function which creates a ‘Add-CalendarBookInPolicy cmdlet in powershell:

function Add-CalendarBookInPolicy {
Param(
$roomName
, $newUser
)
$bookInPolicy = (Get-CalendarProcessing -Identity $roomName).BookInPolicy
$bookInPolicy += $newUser
Set-CalendarProcessing -Identity $roomName -BookInPolicy $bookInPolicy
}


CMD syntax:
Add-CalendarBookInPolicy -Identity $Roomname "MeetingRoom@Test.com" -newUser UserID


To Remove All Users from BookinPolicy:
Set-CalendarProcessing -Identity "MeetingRoom@Test.com"  -BookInPolicy $Nul


To Remove Single User from ResourceDelegate:
function Remove-CalendarResourceDelegate {
Param(
$roomName
, $delegateToRemove
)
$resourceDelegates = (Get-CalendarProcessing -Identity $roomName).ResourceDelegates
$delegateToRemoveIdentity = (Get-Mailbox $delegateToRemove).Identity
$resourceDelegates.Remove($delegateToRemoveIdentity)
Set-CalendarProcessing -Identity $roomName -ResourceDelegates $resourceDelegates
}

#CMD syntax:
Remove-CalendarResourceDelegate -roomName “MeetingRooms@Test.com” -delegateToRemove User1

Note: Custom functions/cmdlet are only available until the current session is active. Next time when you start EMS, again we have to create function/cmdlet. To make it persistent need to write some other codes.