Created
February 19, 2018 12:54
-
-
Save robderickson/582efb78a71aa2a5a12bfbb050e22ec4 to your computer and use it in GitHub Desktop.
Add permission for single user to many mailboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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