This is a code that I have wrote recently to check if an account have Full and SendAs access on target mailboxes in CSV and give the option to choose whether to provide this access or not.
You’ll need to provide two things to get this code working, First the Source account that will need access to the mailboxes. in this case referred to as “ServiceAccount”.
CSV List of Mailbxoes:
You’ll need to provide list of Mailboxes of the users you’d like to provide access to, the List must be user’s Identity either UPN or SMTP would be fine.
The Service account’s Identity must be the UPN attribute.
If you would like to improve this code please do comment or get in touch directly
Thanks
#Connect to Exchange #Connect & Login to ExchangeOnline (MFA) try { Get-Clutter -Identity user@domain.com -ErrorAction Stop > $null } catch { Connect-ExchangeOnline } $Users = import-csv 'C:\CSV\MailboxListIsHere.csv' $ServiceAccount = 'Your Account that will access other Mailboxes' #// Please change the SVC account before running the code foreach ($User in $users) { $Mailbox = $User.Identity #Checking Full Access $Full = Get-MailboxPermission -Identity $Mailbox -User $ServiceAccount If ($Full.AccessRights -eq "FullAccess") { Write-Host -f Green $($ServiceAccount) "Already has Full access to $Mailbox."} Else { $Answer1 = Read-Host "Do you want to assign $($ServiceAccount) Full access to $Mailbox (Yes or No)" If ($Answer1 -eq "Yes") { Try{ Add-MailboxPermission -Identity $Mailbox -User $ServiceAccount -AccessRights FullAccess Write-Host -f DarkGreen $($ServiceAccount) "Send-as access has been added to $Mailbox" } Catch{ ($Full.AccessRights -eq "FullAccess")} } } $SendAs = Get-RecipientPermission -Identity $Mailbox -Trustee $ServiceAccount -AccessRights SendAs if($SendAs.AccessRights -eq "SendAs") { Write-Host -f Green $($ServiceAccount) "Already has SendAs access to $Mailbox." } Else { $Answer2 = Read-Host "Do you want to assign $($ServiceAccount) Send-as access to $Mailbox (Yes or No)" If ($Answer2 -eq "Yes") { Try{ Add-RecipientPermission -Identity $Mailbox -AccessRights SendAs -Trustee $ServiceAccount Write-Host -f Green $($ServiceAccount) "has Send-as access on $Mailbox" } Catch{($SendAs.AccessRights -eq "Sendas")}} else{Exit} } } }
Reset and manage your Active Directory users' Passwords Active Directory is one of the most…
Finding Exchange Database hidden mailboxes. Story:Maybe you have been in this situation before, trying to…
If you're using a Proxy server in your firewall or in your network and have…
Story:I got some clients that have reported some of their users being locked out and…
Story: I got a request from a client who constantly gets CVs and have to…
550 relay not permitted distribution group contact Symptoms When trying to add an external contact…