-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathSet-ExMailboxProperties.ps1
120 lines (103 loc) · 4.09 KB
/
Set-ExMailboxProperties.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
#Requires -Version 5.0
<#
.SYNOPSIS
Connect to Microsoft Exchange Server and and sets the mailbox properties
Only parameters with value are set
.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 Alias
[sr-en] Alias name of the mailbox
.Parameter DisplayName
[sr-en] Display name of the mailbox
.Parameter WindowsEmailAddress
[sr-en] Windows mail address of the mailbox
.Parameter FirstName
[sr-en] User's first name
.Parameter LastName
[sr-en] User's last name
.Parameter Office
[sr-en] User's physical office name or number
.Parameter Phone
[sr-en] User's telephone number
.Parameter ResetPasswordOnNextLogon
[sr-en] User is required to change their password the next time they log on to their mailbox
#>
param(
[Parameter(Mandatory = $true)]
[string]$MailboxId,
[string]$Alias,
[string]$DisplayName ,
[string]$WindowsEmailAddress ,
[string]$FirstName ,
[string]$LastName ,
[string]$Office ,
[string]$Phone ,
[switch]$ResetPasswordOnNextLogon
)
try{
$box = Get-Mailbox -Identity $MailboxId
if($null -ne $box){
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Identity' = $box.UserPrincipalName
'Confirm' = $false
}
if($PSBoundParameters.ContainsKey('Alias') -eq $true ){
Set-Mailbox @cmdArgs -Alias $Alias
}
if($PSBoundParameters.ContainsKey('DisplayName') -eq $true ){
Set-Mailbox @cmdArgs -DisplayName $DisplayName
}
if($PSBoundParameters.ContainsKey('FirstName') -eq $true ){
Set-User @cmdArgs -FirstName $FirstName
}
if($PSBoundParameters.ContainsKey('LastName') -eq $true ){
Set-User @cmdArgs -LastName $LastName
}
if($PSBoundParameters.ContainsKey('Office') -eq $true ){
Set-User @cmdArgs -Office $Office
}
if($PSBoundParameters.ContainsKey('Phone') -eq $true ){
Set-User @cmdArgs -Phone $Phone
}
if($PSBoundParameters.ContainsKey('WindowsEmailAddress') -eq $true ){
Set-Mailbox @cmdArgs -WindowsEmailAddress $WindowsEmailAddress
}
if($PSBoundParameters.ContainsKey('ResetPasswordOnNextLogon') -eq $true ){
Set-User @cmdArgs -ResetPasswordOnNextLogon $ResetPasswordOnNextLogon.ToBool()
}
$resultMessage = @()
$resultMessage += Get-Mailbox -Identity $box.UserPrincipalName | `
Select-Object AccountDisabled,Alias,DisplayName,Name,WindowsEmailAddress, `
ResetPasswordOnNextLogon
$resultMessage += Get-User -Identity $box.UserPrincipalName | `
Select-Object FirstName,LastName,Office,Phone
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{
}