|
# 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 |
|
[email protected], IE\SIMPSON_H |
|
[email protected], IE\BURNS_M |
|
[email protected], IE\SMITHERS_W |
|
[email protected], IE\Desktop Admins |
|
[email protected], IE\SMITH_J |
|
#> |
|
|