This repository was archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSend-SFWelcomeNotification.ps1
More file actions
146 lines (107 loc) · 5.85 KB
/
Send-SFWelcomeNotification.ps1
File metadata and controls
146 lines (107 loc) · 5.85 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
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
<#
.Synopsis
Resends the ShareFile welcome email to the specified user
.DESCRIPTION
The Send-SFWelcomeNotification cmdlet will resend the ShareFile welcome message to an existing ShareFile user.
The user must exist in order to send the ShareFile welcome message otherwise an error will be prompted.
You may specify to send the Welcome message to an employee account or a client account. By default, the cmdlet
sends a welcome notification to a ShareFile client account.
.PARAMETERS
-Email <String[]>
Specifies the email account or accounts you wish to send a Welcome notification. Must be in the format of
myemail@domain.com. If not in the appropriate email pattern, the parameter will not be accepted (e.g. 'notanemail'
would not be a valid email).
-WelcomeMessage <String>
Specifies a welcome message to add to the welcome notification.
-EmployeeAccount [<SwitchParameter>]
Indicates that the given account is a ShareFile employee Account to send the welcome notification to an employee.
By default, the welcome notification is only sent to client accounts.
.EXAMPLE
---------------------------------- EXAMPLE 1 ----------------------------------------------------------
C:\PS>Send-SFWelcomeNotification -email jstrong013@users.noreply.github.com
Description
-----------
The ShareFile client account associated with jstrong013@users.noreply.github.com will have a welcome email sent to them
.EXAMPLE
---------------------------------- EXAMPLE 2 ----------------------------------------------------------
C:\PS>Send-SFWelcomeNotification -email jstrong013@users.noreply.github.com -employeeAccount
Description
-----------
The ShareFile employee account associated with jstrong013@users.noreply.github.com will have a welcome email sent to them
.EXAMPLE
---------------------------------- EXAMPLE 3 ----------------------------------------------------------
C:\PS>Send-SFWelcomeNotification -email jstrong013@users.noreply.github.com -welcomeMessage 'Welcome to
secure file sharing'
Description
-----------
The ShareFile client account associated with jstrong013@users.noreply.github.com will have a welcome email sent to them
with a custom message "Welcome to secure file sharing"
.EXAMPLE
---------------------------------- EXAMPLE 4 ----------------------------------------------------------
C:\PS> jstrong013@users.noreply.github.com | Send-SFWelcomeNotification
Description
-----------
The ShareFile client account associated with jstrong013@users.noreply.github.com will have a welcome email sent to them
#>
function Send-SFWelcomeNotification {
[CmdletBinding()]
Param (
# email The email associated with ShareFile account
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
[ValidateNotNullOrEmpty()]
[ValidatePattern("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")]
[string[]]$email,
# WelcomeMessage an optional value to specify a custom message to the user when sending the welcome email.
[String] $welcomeMessage,
# employeeAccount A switch if the account is an employee ShareFile account
[switch] $employeeAccount
)
Begin {
try {
Add-PSSnapin ShareFile -ErrorAction Stop
}
catch {
Write-Error -Message "ShareFile Snapin is required. Welcome notification not sent."
Return
}
try {
$sfClient = New-SfClient -Name "$env:TEMP\sfClient.sfps" -ErrorAction Stop
}
catch {
Write-Error -Message "Unable to retrieve ShareFile Credentials to run commands. Exiting..."
Exit 13
}
}
Process {
foreach ($identity in $email) {
if (!$employeeAccount) {
$client = Send-SfRequest -Client $sfClient -Entity Accounts\Clients -Method GET | Where-Object { $PSItem.Email -match "^$identity$" }
if ($client -and $client.Count -eq 1) {
Send-SfRequest -Client $sfClient -Entity Users -Method POST -Id $client.Id -Navigation ResendWelcome -Parameters @{ "customMessage" = "$welcomeMessage" }
Write-Verbose -Message "Welcome Message sent to $($client.Name) at email address $($client.Email) with message '$($welcomeMessage)'"
}
else {
Write-Error -Message "Welcome message failed to send for $email." -RecommendedAction "Check if ShareFile Account exists or verify it is a client account."
}
}
if ($employeeAccount) {
$employee = Send-SfRequest -Client $sfClient -Entity Accounts\Employees -Method GET | Where-Object { $PSItem.Email -match "^$identity$" }
if ($employee -and $employee.Count -eq 1) {
Send-SfRequest -Client $sfClient -Entity Users -Method POST -Id $employee.Id -Navigation ResendWelcome -Parameters @{ "customMessage" = "$welcomeMessage" }
Write-Verbose -Message "Welcome Message sent to $($employee.Name) at email address $($employee.Email) with message '$($welcomeMessage)'"
}
else {
Write-Error -Message "Welcome message failed to send for $email." -RecommendedAction "Check if ShareFile Account exists or verify it is an Employee account."
}
}
} # end forEach
}
End {
# Remove stored Client Credentials
if (Test-Path "$env:Temp\sfclient.sfps") {
Remove-Item -Path "$env:TEMP\sfclient.sfps" -Force
}
}
} # End Send-SFWelcomeNotification