Adding dynamic security group members to shared mailbox permissions script

1.8k Views Asked by At

Trying to do something like this to add members of an azure dynamic security group to the shared mailbox they belong to based on CSV info

Import-Csv C:\users\jeiger\desktop\kiosknames.csv | ForEach-Object {

foreach ($kioskgroup in $_.kioskgroupname){
    foreach ($user in $kioskgroup){
        Add-MailboxPermission $_.kioskemail -User $user -AccessRights FullAccess -AutoMapping $false
        Add-RecipientPermission $_.kioskemail -AccessRights SendAs -Trustee $user
    }
}

}

Headers would read something like: kioskgroupname and kioskemail

1

There are 1 best solutions below

0
On

Make sure you install the Azure AD Module and EXO V2 module.

Refer to this script:

$username = "{username of admin}"
$password = "{password of admin}"
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
Connect-AzureAD -Credential $Credential

$DynamicAADGroupMembers = Get-AzureADGroupMember -ObjectId "{object id of the azure dynamic security group}"

Connect-ExchangeOnline -Credential $Credential

$sharedMailbox = "{email address of the shared mailbox}"

foreach ($user in $DynamicAADGroupMembers){
    Add-MailboxPermission $sharedMailbox -User $user.ObjectId -AccessRights FullAccess -AutoMapping $false
    Add-RecipientPermission $sharedMailbox -AccessRights SendAs -Trustee $user.ObjectId
}