Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script will change a user mailbox into a shared mailbox and prompt you if you want to add a delegate.
- # define functions
- function Get-UserInfo{
- [string]$script:mailbox = Read-Host "please enter the email address of the user you should like to convert"
- }
- function Set-SharedMbox {
- Write-Host "Checking if $mailbox is already shared type..."
- $state = $(Get-Mailbox -Identity $mailbox | Select-Object -ExpandProperty RecipientTypeDetails)
- if($state -eq "UserMailbox"){
- Set-Mailbox -identity $mailbox -Type Shared
- Write-Host "Successfully converted $mailbox to a shared mailbox."
- }
- elseif($state -eq "SharedMailbox"){
- Write-Host "Mailbox $mailbox is already a shared mailbox."
- }
- }
- function Edit-Delegates {
- param (
- [string[]]$delegate,
- [string[]]$rights
- )
- Add-MailboxPermission -Identity "$mailbox" -User "$delegate" -AccessRights FullAccess
- if ($?){
- Write-Host "Added user $delegate as a delegate of $mailbox."
- }
- if ($rights -eq 2){
- Add-RecipientPermission -Identity "$mailbox" -Trustee "$delegate" -AccessRights SendAs
- if ($?){
- Write-Host "Added sending rights for $delegate on mailbox $mailbox."
- }
- }
- }
- function Read-Choice {
- $script:choice = Read-Host "Would you like to add a delegate user now?"
- }
- # Actual script
- $adminuser = Read-Host 'Enter the email address of an admin user'
- Connect-ExchangeOnline -UserPrincipalName $adminuser
- # clear the screen to avoid the cmdlet vomit
- Clear-Host
- Get-UserInfo
- if([string]::IsNullOrWhiteSpace($mailbox)){
- Write-Host "You must enter an email address."
- Write-Host "Please try again."
- Get-UserInfo
- }
- else{
- Set-SharedMbox
- }
- Read-Choice
- if ($choice -eq "y"){
- $delegate = Read-Host "Please enter the email address for the delegated user"
- Write-Host "`n`n"
- Write-Host "Please enter the access rights you would like this user to have."
- Write-Host "1. FullAccess (full access to the mailbox, but cannot send.)"
- Write-Host "2. FullAccess + SendAs (Same as above, but allows sending from the delegated mailbox.)"
- $rights = Read-Host "Enter your choice"
- Clear-Host
- Edit-Delegates $delegate $rights
- }
- elseif ($choice -eq "n"){
- Write-Output "Goodbye."
- }
- else{
- Write-Output "Invalid entry. Please try again."
- Read-Choice
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement