-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathSet-ExMailboxQuotas.ps1
190 lines (170 loc) · 7.54 KB
/
Set-ExMailboxQuotas.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#Requires -Version 5.0
<#
.SYNOPSIS
Connect to Microsoft Exchange Server and and sets the mailbox quotas
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/Exchange/MailBoxes
.Parameter MailboxId
[sr-en] Alias, Display name, Distinguished name, SamAccountName, Guid or user principal name of the mailbox from which to set properties
.Parameter Unit
[sr-en] Units
.Parameter UseDatabaseQuotaDefaults
[sr-en] Alias name of the mailbox
.Parameter ProhibitSendQuota
[sr-en] Size limit for new messages on the mailbox.
The value must be less than or equal to the ProhibitSendReceiveQuota value
.Parameter ProhibitSendReceiveQuota
[sr-en] Size limit for send or receive new messages on the mailbox.
The value must be greater than or equal to the ProhibitSendQuota or IssueWarningQuota values
.Parameter RecoverableItemsQuota
[sr-en] Maximum size for the Recoverable Items folder of the mailbox
.Parameter RecoverableItemsWarningQuota
[sr-en] Warning threshold for the size of the Recoverable Items folder for the mailbox
.Parameter IssueWarningQuota
[sr-en] Warning threshold for the size of the mailbox
.Parameter CalendarLoggingQuota
[sr-en] Maximum size of the log in the Recoverable Items folder of the mailbox that stores changes to calendar items
.Parameter ArchiveQuota
[sr-en] Maximum size for the user's archive mailbox
.Parameter ArchiveWarningQuota
[sr-en] Warning threshold for the size of the user's archive mailbox
.Parameter RulesQuota
[sr-en] Limit for the size of Inbox rules for the mailbox (in bytes)
#>
param(
[Parameter(Mandatory = $true)]
[string]$MailboxId,
[ValidateSet('MB','GB')]
[string]$Unit = 'GB',
[bool]$UseDatabaseQuotaDefaults = $false,
[ValidateRange(0, [double]::MaxValue)]
[double]$ProhibitSendQuota ,
[ValidateRange(0, [double]::MaxValue)]
[double]$ProhibitSendReceiveQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$RecoverableItemsQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$RecoverableItemsWarningQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$ArchiveQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$ArchiveWarningQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$CalendarLoggingQuota,
[ValidateRange(0, [double]::MaxValue)]
[double]$IssueWarningQuota,
[int]$RulesQuota
)
try{
[uint64]$Script:setSize
$Script:sizeUnit = '1GB'
if($Unit -eq "MB"){
$Script:sizeUnit = '1MB'
}
if(($ProhibitSendQuota -gt 0) -and ($ProhibitSendReceiveQuota -gt 0)){
if($ProhibitSendQuota -gt $ProhibitSendReceiveQuota){
$ProhibitSendQuota = $ProhibitSendReceiveQuota
}
}
if(($RecoverableItemsQuota -gt 0) -and ($RecoverableItemsWarningQuota -gt 0)){
if($RecoverableItemsWarningQuota -gt $RecoverableItemsQuota){
$RecoverableItemsWarningQuota = $RecoverableItemsQuota
}
}
if(($ArchiveQuota -gt 0) -and ($ArchiveWarningQuota -gt 0)){
if($ArchiveWarningQuota -gt $ArchiveQuota){
$ArchiveWarningQuota = $ArchiveQuota
}
}
if(($CalendarLoggingQuota -gt 0) -and ($RecoverableItemsQuota -gt 0)){
if($CalendarLoggingQuota -gt $RecoverableItemsQuota){
$CalendarLoggingQuota = $RecoverableItemsQuota
}
}
if(($IssueWarningQuota -gt 0) -and ($ProhibitSendReceiveQuota -gt 0)){
if($IssueWarningQuota -gt $ProhibitSendReceiveQuota){
$IssueWarningQuota = $ProhibitSendReceiveQuota
}
}
$box = Get-Mailbox -Identity $MailboxId
if($null -ne $box){
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Identity' = $box.UserPrincipalName
'Confirm' = $false
'Force' = $null
'UseDatabaseQuotaDefaults' = $UseDatabaseQuotaDefaults
}
if($UseDatabaseQuotaDefaults -eq $true)
{
Set-Mailbox @cmdArgs
}
else{
if($ProhibitSendReceiveQuota -gt 0 ){
$Script:setSize = [math]::Round($ProhibitSendReceiveQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -ProhibitSendReceiveQuota $Script:setSize
}
if($ProhibitSendQuota -gt 0 ){
$Script:setSize = [math]::Round($ProhibitSendQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -ProhibitSendQuota $Script:setSize
}
if($RecoverableItemsQuota -gt 0 ){
$Script:setSize = [math]::Round($RecoverableItemsQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -RecoverableItemsQuota $Script:setSize
}
if($RecoverableItemsWarningQuota -gt 0 ){
$Script:setSize = [math]::Round($RecoverableItemsWarningQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -RecoverableItemsWarningQuota $Script:setSize
}
if($ArchiveQuota -gt 0 ){
$Script:setSize = [math]::Round($ArchiveQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -ArchiveQuota $Script:setSize
}
if($ArchiveWarningQuota -gt 0 ){
$Script:setSize = [math]::Round($ArchiveWarningQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -ArchiveWarningQuota $Script:setSize
}
if($CalendarLoggingQuota -gt 0 ){
$Script:setSize = [math]::Round($CalendarLoggingQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -CalendarLoggingQuota $Script:setSize
}
if($IssueWarningQuota -gt 0 ){
$Script:setSize = [math]::Round($IssueWarningQuota * $Script:sizeUnit,0)
Set-Mailbox @cmdArgs -IssueWarningQuota $Script:setSize
}
if($RulesQuota -gt 0 ){
Set-Mailbox @cmdArgs -RulesQuota $RulesQuota
}
}
$resultMessage = @()
$resultMessage += Get-Mailbox -Identity $box.UserPrincipalName | `
Select-Object @('UseDatabaseQuotaDefaults','ProhibitSendQuota','ProhibitSendReceiveQuota', `
'RecoverableItemsQuota','RecoverableItemsWarningQuota','CalendarLoggingQuota', `
'IssueWarningQuota','RulesQuota','ArchiveQuota','ArchiveWarningQuota')
if($SRXEnv) {
$SRXEnv.ResultMessage = $resultMessage
}
else{
Write-Output $resultMessage
}
}
else{
if($SRXEnv) {
$SRXEnv.ResultMessage = "Mailbox $($MailboxId) not found"
}
Throw "Mailbox $($MailboxId) not found"
}
}
catch{
throw
}
finally{
}