-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemove-AutoMapping.ps1
57 lines (45 loc) · 1.5 KB
/
Remove-AutoMapping.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<#
.Synopsis
Removes automapped Exchange 2013 mailboxes from Outlook.
.DESCRIPTION
Removes automapped Exchange 2013 mailboxes from Outlook while preserving the underlying access rights.
.EXAMPLE
Remove-AutoMapping -Identity scollins -User ccolding
Removes the automapped mailbox of scollins for ccolding.
.PARAMETER Identity
The automapped mailbox you're removing.
.PARAMETER User
The user you're removing the automapped mailbox from.
#>
function Remove-AutoMapping
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
Position=0)]
[string[]]$Identity,
[Parameter(Mandatory=$true,
Position=1)]
[string]$User
)
Begin
{
}
Process
{
foreach($Mailbox in $Identity){
$AccessRights = Get-MailboxPermission -Identity $Mailbox | where {$_.User -like "*$User*" -and $_.IsInherited -like "False" -and $_.Deny -like "False"}
if($AccessRights -ne $null){
Add-MailboxPermission -Identity $Mailbox -User $User -AccessRights $AccessRights.AccessRights -AutoMapping $false
}
else{
Add-MailboxPermission -Identity $Mailbox -User $User -AccessRights ReadPermission -AutoMapping $false
Remove-MailboxPermission -Identity $Mailbox -User $User -AccessRights ReadPermission -Confirm:$false
}
}
}
End
{
}
}