Add-SendAsPermission.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Add-SendAsPermission
{
  <#
      .SYNOPSIS
      Adds SendAs Extended Right to target user
      .EXAMPLE
      Add-SendAsPermission -enduser steve -targetmailbox bob
      Adds SendAs permission on bob's mailbox for end user steve.
  #>

  param
  (
    [String]
    [Parameter(Mandatory)]
    $enduser,

    [Parameter(Mandatory)]
    [String]
    $targetmailbox
  )

  Confirm-ExchangeOnlineConnection -ConnectIfDisconnected
    
  try 
  {
    #Add-RecipientPermission -Identity "$($targetmailbox.samaccountname)" -Trustee "$($enduser.samaccountname)" -AccessRights SendAs -Verbose
    Add-RecipientPermission -Identity $targetmailbox -Trustee $enduser -AccessRights SendAs -Verbose
  }
  catch 
  {
    Write-Output -InputObject 'Error in adding Recipient permissions.'
    Return $_.Exception
  }
}