Skip to content

Instantly share code, notes, and snippets.

@robderickson
Created February 19, 2018 12:54
Show Gist options
  • Save robderickson/582efb78a71aa2a5a12bfbb050e22ec4 to your computer and use it in GitHub Desktop.
Save robderickson/582efb78a71aa2a5a12bfbb050e22ec4 to your computer and use it in GitHub Desktop.
Add permission for single user to many mailboxes
function Set-CustomUserMailboxPermission {
[cmdletbinding()]
param (
[parameter(ValueFromPipeline,Mandatory)]
[string]$User,
[parameter(ValueFromPipeline,Mandatory)]
[string[]]$Mailbox,
[parameter(Mandatory)]
[PSCredential]$Credential
)
begin {
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $Session
}
process {
foreach ($Box in $Mailbox) {
Add-MailboxPermission -Identity $Box -AccessRights FullAccess -InheritanceType All -AutoMapping:$true -User $User
Add-RecipientPermission -Identity $Box -AccessRights SendAs -Confirm:$false -Trustee $User
}
}
end {
Remove-PSSession $Session
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment