-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-MailboxAccessList.ps1
More file actions
64 lines (57 loc) · 2.69 KB
/
Get-MailboxAccessList.ps1
File metadata and controls
64 lines (57 loc) · 2.69 KB
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
58
59
60
61
62
63
64
function MailboxAccess {
PARAM (
[Parameter(Mandatory=$true)]$EmailAddress
)
if(-not($EmailAddress)) {
Throw "You must supply a value for -Address"
}
$Address = "$EmailAddress"
#Filter out default users and permissions
$MemberList = (Get-MailboxPermission $Address | select user | Where-Object {$_.user -notlike "OREGONSTATE*"} | Where-Object {$_.user -notlike "NT*"} | Where-Object {$_.user -notlike "FS*"} | Where-Object {$_.user -notlike "*CN_ITAdmins*"}) | Where-Object {$_.user -notlike "FS_*"}| Out-String
$split = $MemberList.Split("`n")
[string[]]$NameArr = @()
[string[]]$GroupList = @()
$AccessList = @()
foreach ($item in $split) {
if(($item -notlike "*CN*") -and ($item.Length -gt 8))
{
#do nothing
} else {
$tempsplit = $item.Split("\")
$NameArr += $tempsplit | Where-Object {$_ -notlike "cn"} | Where-Object {$_ -notlike "FS*"}
}
}
foreach ($item in $NameArr) {
$StringArr += $Item | Out-String
}
$FinArr = $StringArr.Split("`n")
if([string]::IsNullOrWhiteSpace($FinArr)) {
Write-Warning "No special premission were found on this mailbox."
} else {
#If there is a group that contains "Mailbox" then print that, else print the usernames
$MainGroup = $FinArr | Where-Object {$_ -like "*mailbox*"}
Write-Host "Groups that give access: " $MainGroup
foreach ($item in $FinArr) {
#Remove weird white spaces
$item = $item.Trim()
#Check for ONID
if($item.Length -le 8) {
if([string]::IsNullOrEmpty($item) -or [string]::IsNullOrWhiteSpace($item)){
#Ignore that item
}else{
$AccessList += "Added direclty: " +$item
}
} else {
$AccessList += (Get-ADGroupMember -Identity $item -Server tss.oregonstate.edu -Recursive | select name | Out-String)
}
}
}
#Format and print the output
$AccessList = $AccessList.Split("`n")
$AccessList = $AccessList | Where-Object{$_ -notlike "*--*"} | Where-Object{$_ -notlike "*name*"}
Write-Host "`nUsers who have access:"
#Needed to remove unwanted new lines
$AccessList[1..$AccessList.Length]
}
#remove after testing
MailboxAccess -EmailAddress BAF.Scheduler@oregonstate.edu