-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-MailboxSendOnBehalfRights.ps1
94 lines (87 loc) · 6.82 KB
/
Get-MailboxSendOnBehalfRights.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function Get-MailboxSendOnBehalfRights {
<#
.SYNOPSIS
Retrieves a list of mailbox sendonbehalf permissions
.DESCRIPTION
Gathers a list of users with sendonbehalf permissions for a mailbox.
.PARAMETER MailboxNames
Array of mailbox names in string format.
.PARAMETER MailboxObject
One or more mailbox objects.
.LINK
http://www.the-little-things.net
.NOTES
Version
1.1.0 11/04/2014
- Minor structual changes and input parameter updates
1.0.0 10/04/2014
- Initial release
Author : Zachary Loeber
.EXAMPLE
Get-MailboxSendOnBehalfRights -MailboxName "Test User1" -Verbose
Description
-----------
Gets the sendonbehalf permissions for "Test User1" and shows verbose information.
.EXAMPLE
Get-MailboxSendOnBehalfRights -MailboxName "user1","user2" | Format-List
Description
-----------
Gets the sendonbehalf permissions for "user1" and "user2" and returns the info as a format-list.
.EXAMPLE
(Get-Mailbox -Database "MDB1") | Get-MailboxSendOnBehalfRights | Where {$_.SendOnBehalf -notlike "S-1-*"}
Description
-----------
Gets all mailboxes in the MDB1 database and pipes it to Get-MailboxSendOnBehalfRights and returns the
sendonbehalf permissions as an autosized format-table containing the Mailbox and sendonbehalf User.
#>
[CmdLetBinding(DefaultParameterSetName='AsString')]
param(
[Parameter(ParameterSetName='AsStringArray', Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage="Enter an Exchange mailbox name")]
[string[]]$MailboxNames,
[Parameter(ParameterSetName='AsMailbox', Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage="Enter an Exchange mailbox name")]
$MailboxObject,
[Parameter(HelpMessage='Includes unresolved names (typically deleted accounts).')]
[switch]$ShowAll
)
begin {
Write-Verbose "$($MyInvocation.MyCommand): Begin"
$Mailboxes = @()
}
process {
switch ($PSCmdlet.ParameterSetName) {
'AsStringArray' {
try {
$Mailboxes = @($MailboxNames | Foreach {Get-Mailbox $_ -erroraction Stop})
}
catch {
Write-Warning = "$($MyInvocation.MyCommand): $_.Exception.Message"
}
}
'AsMailbox' {
$Mailboxes = @($MailboxObject)
}
}
$Mailboxes | Foreach {
Write-Verbose "$($MyInvocation.MyCommand): Processing Mailbox $($Mailbox.Name)"
$sendbehalfperms = @($_ | Select -expand grantsendonbehalfto | Select -expand rdn | Select Unescapedname)
if ($sendbehalfperms.Count -gt 0)
{
if ($ShowAll)
{
$sendbehalfperms = ($sendbehalfperms).Unescapedname
}
else
{
$sendbehalfperms = ($sendbehalfperms | Where {$_.Unescapedname -notlike 'S-1-*'}).Unescapedname
}
New-Object psobject -Property @{
'Mailbox' = $_.Name
'SendOnBehalf' = $sendbehalfperms
}
}
}
}
end {
Write-Verbose "$($MyInvocation.MyCommand): End"
}
}