Skip to content

Instantly share code, notes, and snippets.

@micmaher
Created April 10, 2016 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmaher/9a9f2956f1ff3f41e7c05b3b0c876e8f to your computer and use it in GitHub Desktop.
Save micmaher/9a9f2956f1ff3f41e7c05b3b0c876e8f to your computer and use it in GitHub Desktop.
Change Shared Mailbox Permissons
# Michael Maher
# 22/5/13
# Get ACLs from CSV and write to AD
$arrRecord = @()
$spreadsheet = Import-Csv C:\scripts\ACLs2.csv
# Get just the mailbox name which will be used to create group names later
# Store this in an array so we can sort it and get unique values later
# Also need a second array with the full email address and ACL for applying permissions later
foreach ($row in $spreadsheet) {
$arrRecord = $arrRecord + $row.contosoSMTPaddr -replace '@contoso.com', ''
}
# We don't want duplicates when creating the groups
$uniqueMailbox = $arrRecord | Sort | Get-Unique | Write-Output
# Now create a group to define access to each shared mailbox
Write-Output "###### 1. Creating New Groups and Granting Access to Shared Mailboxes ######"
Start-Sleep -s 1
foreach ($name in $uniqueMailbox) {
$name = $name.trim()
Write-Output "net group /add /domain shr$name"
net group /add /domain shr$name
Start-Sleep -s 1
$emailAddr = $name + "@contoso.com"
# Grant Full Mailbox Access
Write-Output "Add-MailboxPermission $emailAddr -User shr$name -AccessRights FullAccess"
Add-MailboxPermission $emailAddr -User shr$name -AccessRights FullAccess
Start-Sleep -s 1
}
Write-Output ""
Write-Output "######################## Stage 1 Complete #################################"
Start-Sleep -s 1
# Add the users into the new group
Write-Output "################ 2. Adding Users to New Groups ############################"
Start-Sleep -s 1
foreach ($row in $spreadsheet) {
$abbrevGroupname = $row.contosoSMTPaddr -replace '@contoso.com', ''
$userToAdd = $row.groupName -replace 'IE\\', ''
$userToAdd = $userToAdd.trim()
Write-Output "net group shr$abbrevGroupname /add ""$userToAdd"" /domain"
Start-Sleep -s 1
net group shr$abbrevGroupname /add ""$userToAdd"" /domain
}
Write-Output ""
Write-Output "######################## Stage 2 Complete #################################"
Start-Sleep -s 1
<# Sample C:\Temp\ACLs.csv
smtpaddress, GroupName
Accounts.Receivable.LMK@contoso.com, IE\SIMPSON_H
Accounts.Receivable.LMK@contoso.com, IE\BURNS_M
Chargebacks@contoso.com, IE\SMITHERS_W
Chargebacks@contoso.com, IE\Desktop Admins
Chargebacks@contoso.com, IE\SMITH_J
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment