-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSend-PlexLibraryUpdate.ps1
More file actions
548 lines (468 loc) · 22 KB
/
Send-PlexLibraryUpdate.ps1
File metadata and controls
548 lines (468 loc) · 22 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<#
.SYNOPSIS
Pull a list of recently-added movies from Plex and send a listing via email
.DESCRIPTION
This script will send to a specified recipient a list of movies added to Plex in the past 7 days (or as specified).
This list will include information pulled dynamically from OMDBapi.com, the Open Movie Database.
.PARAMETERS
See param block for descriptions of available parameters
.EXAMPLE
PS C:\>Send-PlexLibraryUpdate.ps1
.EXAMPLE
PS C:\>Send-PlexLibraryUpdate.ps1 -Url 10.0.0.100 -Port 12345 -Days 14 -EmailTo test@test.com -ExcludeLib 11 -PreventSendingEmptyList -OmitVersionNumber
.NOTES
Requires CredentialManager module.
> Install-Module CredentialManager
> New-StoredCredential -Target plexToken -UserName plex -Password [Plex token] -Type Generic -Persist LocalMachine
> New-StoredCredential -Target tmdb.org -UserName tmdb -Password [TMDB token] -Type Generic -Persist LocalMachine
> New-StoredCredential -Target PlexCheck -UserName [Email address] -Password [Email password] -Type Generic -Persist LocalMachine
To find your Plex token, check here: https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token
#>
param(
# Optionally specify IP of the server we want to connect to
[string] $PlexUrl = 'http://127.0.0.1',
# Optionally define a custom port
[int] $PlexPort = '32400',
# Optionally specify a number of days back to report
[int] $Days = 7,
# Optionally define the address to send the report to
# If not otherwise specified, send to the From address
[string] $EmailTo = 'default',
# Specify the SMTP server address (if not gmail)
# Assumes SSL, because security!
[string] $SMTPserver = 'smtp.gmail.com',
# Specify the SMTP server's SSL port
[int] $SMTPport = '587',
# Specify the Library Name of any libraries you'd like to exclude
[string[]] $ExcludeLib = @(),
# Specify whether to prevent sending email if there are no additions
[switch] $PreventSendingEmptyList,
# Specify whether to omit the Plex Server version number from the email
[switch] $OmitVersionNumber,
# Specify whether to pick a random collection to feature
[switch] $FeatureRandomCollection,
# Specify a specific collection to feature by name (overrides $FeatureRandomCollection unless the specified collection isn't found)
[string] $FeatureSpecificCollection,
# Specify whether to upload all movie posters to Imgur rather than use TVDB posters
[Parameter (ParameterSetName = 'imgur')]
[switch] $UploadPostersToImgur,
# Specify the location of the file to store Imgur links in for movies/collections
[Parameter (Mandatory = $true,
ParameterSetName = 'imgur')]
[ValidateScript ({
if(-Not ($_ | Test-Path) ){
throw "File or folder does not exist"
}
if(-Not ($_ | Test-Path -PathType Leaf) ){
throw "The Path argument must be a file. Folder paths are not allowed."
}
if($_ -notmatch "(\.csv)"){
throw "The file specified in the path argument must be either of type msi or exe"
}
return $true
})]
[System.IO.FileInfo] $ImgurFilePath
)
#region Invoke-ImgurUpload
function Invoke-ImgurUpload {
param (
[Parameter (Mandatory = $true)]
[string] $ClientID,
[Parameter (Mandatory = $true)]
[string] $ImageBase64,
[Parameter (Mandatory = $true)]
[ValidateScript ({
if(-Not ($_ | Test-Path) ){
throw "File or folder does not exist"
}
if(-Not ($_ | Test-Path -PathType Leaf) ){
throw "The Path argument must be a file. Folder paths are not allowed."
}
if($_ -notmatch "(\.csv)"){
throw "The file specified in the path argument must be either of type msi or exe"
}
return $true
})]
[System.IO.FileInfo] $FilePath,
[Parameter (Mandatory = $true)]
[string] $PlexPath
)
Try {
$csv = Import-CSV -Path $FilePath -ErrorAction Stop
}
Catch {
Throw $_.Exception
}
if ($csv.PlexPath -contains $PlexPath) {
Write-Verbose "Item already exists in $FilePath. Returning existing Imgur record."
Return ($csv | Where-Object {$_.PlexPath -eq $PlexPath})
}
else {
Write-Verbose "Item does not exist in $FilePath. Uploading to Imgur."
$imgurHeader = @{Authorization = "Client-ID $ClientID"; "Content-Type" = "application/json"}
Try {
$imgurResponse = Invoke-RestMethod -Method Post -Uri "https://api.imgur.com/3/upload" -Headers $imgurHeader -Body (@{image = "$ImageBase64"; type = "base64"} | ConvertTo-Json) -ErrorAction Stop
Write-Verbose "Uploaded image to Imgur: $($imgurResponse.Data.link)"
}
Catch {
Throw $_.Exception
}
$newRowHash = @{PlexPath = $PlexPath; ImgurLink = $($imgurResponse.data.link); DeleteHash = $($imgurResponse.data.deletehash); DateAdded = $(Get-Date -Format 'yyyy-MM-dd'); Height = $imgurResponse.data.height; Width = $imgurResponse.data.width}
$newRow = New-Object PsObject -Property $newRowHash
Export-CSV $FilePath -InputObject $newRow -Append -Force -NoTypeInformation
Return $newRow
}
}
#endregion
#region import credentials
if (-not (Get-Module CredentialManager)) {
Try {
Import-Module CredentialManager -ErrorAction Stop
} Catch {
Write-Host "Failed to load CredentialManager. Aborting."
Throw $_.Exception
}
}
Try {
$tmdbToken = (Get-StoredCredential -Target tmdb.org -ErrorAction Stop).GetNetworkCredential().Password
if (-not $tmdbToken) {
Throw "No TMDB token found."
}
Write-Verbose "Retrieved TMDB token."
}
Catch {
Write-Error "Failed to retrieve TMDB token."
Throw $_.Exception
}
Try {
$plexToken = (Get-StoredCredential -Target PlexToken -ErrorAction Stop).GetNetworkCredential().Password
if (-not $plexToken) {
Throw "No Plex token found."
}
Write-Verbose "Retrieved Plex token."
}
Catch {
Write-Error "Failed to retrieve Plex token."
Throw $_.Exception
}
Try {
$emailCreds = Get-StoredCredential -Target PlexCheck -ErrorAction Stop
if (-not $emailCreds) {
Throw "No email credentials found."
}
Write-Verbose "Retrieved email credentials."
}
Catch {
Throw $_.Exception
}
Try {
$imgurCreds = Get-StoredCredential -Target imgur -ErrorAction Stop
if (-not $imgurCreds) {
Throw "No imgur credentials found."
}
Write-Verbose "Retrieved imgur credentials."
}
Catch {
Throw $_.Exception
}
#endregion
#region Declarations
$epoch = Get-Date '1/1/1970'
$startDate = Get-Date (Get-Date).AddDays(-$days) -UFormat "%s"
$imgPlex = "http://i.imgur.com/RyX9y3A.jpg"
$searchURL = "https://api.themoviedb.org/3/find"
$imdbIDformat = [Regex]::new('tt\d{7,8}')
$tvdbIDformat = [Regex]::new('[1-9]\d*')
$style = @"
<html>
<head>
<style type="text/css">
table
{
width: 95%
}
td
{
padding: 5px;
vertical-align:middle;
text-align: left;
}
a
{
color: #1a4b7f;
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
a:visited
{
color: #636;
}
.center
{
text-align: center;
}
ul
{
list-style-position: outside;
}
h1
{
display: block;
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
h2
{
display: block;
font-size: 1.5em;
margin-top: 0.83em;
margin-bottom: 0.83em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
@media (max-width: 768px)
{
table {
width: 100%;
}
td {
display: block;
width: 100%;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
a {
text-decoration: underline;
}
}
</style>
</head>
<body>
"@
#endregion
$response = Invoke-RestMethod "$PlexUrl`:$PlexPort/library/recentlyAdded/?X-Plex-Token=$plexToken" -Headers @{"accept"="application/json"} | Select-Object -ExpandProperty MediaContainer | Select-Object -ExpandProperty Metadata
$response = $response | Where-Object {$_.addedAt -gt $startDate -and $_.librarySectionTitle -notin $ExcludeLib}
# Grab those libraries
$movies = $response |
Where-Object {$_.type -eq 'movie'} |
Sort-Object addedAt
$tvShows = $response |
Where-Object {$_.type -eq 'season'} |
Group-Object parentTitle
if ($($movies | Measure-Object).count -gt 0) {
# Initialize the counters and lists
$movieCount = 0
$movieList = "<h2>Movies:</h2><br/><table>"
foreach ($movie in $movies) {
# TMDB rate-limits. Currently 40 requests every 10 seconds, so sleep 10 seconds every 15 movies to be safe (2 calls per movie)
# https://developers.themoviedb.org/3/getting-started/request-rate-limiting
if ($movieCount -gt 1 -AND $movieCount%15 -eq 0) {
Write-Verbose "On movie $movieCount, waiting 10 seconds..."
Start-Sleep -Seconds 10
}
$posterFail = $false
$movieCount++
Write-Verbose "Looking up $($movie.title) ($movieCount / $($movies | Measure-Object | Select-Object -ExpandProperty Count))."
# Retrieve movie info from The Movie Database
$simpleResponse = (Invoke-RestMethod "$searchURL/$($imdbIDformat.Matches($movie.guid).value)?api_key=$tmdbToken&language=en-US&external_source=imdb_id").movie_results
# Assuming we have a valid response, pull detailed info on the movie
if ($simpleResponse.id) {
$detailedResponse = (Invoke-RestMethod "https://api.themoviedb.org/3/movie/$($simpleResponse.id)?api_key=$tmdbToken&language=en-US")
}
if ($detailedResponse.Title) {
if ($UploadPostersToImgur) {
Try {
Invoke-WebRequest -Uri "$PlexUrl`:$PlexPort$($movie.thumb)?X-Plex-Token=$plexToken" -OutVariable moviePoster -ErrorAction Stop
$imgurLink = Invoke-ImgurUpload -ClientID $imgurCreds.UserName -ImageBase64 ([convert]::ToBase64String($moviePoster.content)) -PlexPath $movie.thumb -FilePath $ImgurFilePath -ErrorAction Stop
$movieList += "<tr><td><img src=`"$($imgurLink.ImgurLink)`" width=154px height=$(154/$($imgurLink.width)*$($imgurLink.height)) class=`"center`"></td>"
}
Catch {
$posterFail = $true
}
}
else {
if ($detailedResponse.poster_path) {
$movieList += "<tr><td><img src=`"https://image.tmdb.org/t/p/w154$($detailedResponse.poster_path)`" class=`"center`"></td>"
} else {
$posterFail = $true
}
}
# If the poster was unavailable, substitute a Plex logo
if ($posterFail) {$movieList += "<tr><td><img src=`"$imgPlex`" height=154px width=154px class=`"center`"></td>"}
$movieList += "<td><b><a href=`"http://www.imdb.com/title/$($detailedResponse.imdb_ID)/`">$($detailedResponse.title)</a></b> ($(($detailedResponse.release_date).split('-')[0]))"
$movieList += "<ul><li><i>Genre$(if($detailedResponse.Genres.count -gt 1){"s"}):</i> $($detailedResponse.Genres.name -join ', ')</li>"
$movieList += "<li><i>Rating:</i> $($movie.contentRating)</li>"
$movieList += "<li><i>Runtime:</i> $($detailedResponse.runtime) minutes</li>"
$movieList += "<li><i>Star$(if($detailedResponse.role.count -gt 1){"s"}):</i> $($movie.role.tag -join ', ')</li>"
$movieList += "<li><i>Plot:</i> $($movie.summary)</li>"
$movieList += "<li><i>IMDB rating:</i> $(($detailedResponse.vote_average).toString("#.#"))/10</li>"
$movieList += "<li><i>Added:</i> $(Get-Date $epoch.AddSeconds($movie.addedAt) -Format 'MMMM d')</li></ul></td>"
}
else {
# If the movie couldn't be retrieved, fail gracefully
$movieList += "<tr><td><img src=`"$imgPlex`" height=154px width=154px class=`"center`"></td>"
$movieList += "<td><b>$($movie.title)</b> ($($movie.year))"
$movieList += "<ul><li>No additional information available.</li></ul></td>"
}
$movieList += "</tr>"
Clear-Variable simpleResponse, detailedResponse, posterFail
}
$movieList += "</table><br/>"
}
if ($($tvShows | Measure-Object).Count -gt 0) {
# Initialize the counters and lists
$tvCount = 0
$tvList = "<h2>TV Seasons:</h2><br/><table>"
foreach ($show in $tvShows) {
# Sleep every 15 shows for that TMDB rate limiting, even just the first one since we probably just did a bunch of movies.
if ($tvCount%15 -eq 0) {
Write-Verbose "On show $tvCount, waiting 10 seconds..."
Start-Sleep -Seconds 10
}
# Count it!
$tvCount++
$posterFail = $false
$tvdbID = ($tvdbIDformat.matches($show.group.guid).value)[0]
Write-Verbose "Looking up $($show.name) ($tvCount / $($tvShows | Measure-Object | Select-Object -ExpandProperty Count))."
# Retrieve movie info from The Movie Database
$simpleResponse = (Invoke-RestMethod "$searchURL/$tvdbID`?api_key=$tmdbToken&language=en-US&external_source=tvdb_id").tv_results
# Assuming we have a valid response, pull detailed info on the movie
if ($simpleResponse.id) {
$detailedResponse = (Invoke-RestMethod "https://api.themoviedb.org/3/tv/$($simpleResponse.id)?api_key=$tmdbToken&language=en-US")
$contentRating = (Invoke-RestMethod "https://api.themoviedb.org/3/tv/$($simpleResponse.id)/content_ratings?api_key=$tmdbToken&language=en-US").Results | Where-Object {$_.iso_3166_1 -eq 'US'} | Select-Object -ExpandProperty Rating
$imdbID = (Invoke-RestMethod "https://api.themoviedb.org/3/tv/$($simpleResponse.id)/external_ids?api_key=$tmdbToken&language=en-US").imdb_id
}
if ($detailedResponse.id) {
if ($UploadPostersToImgur) {
Try {
Invoke-WebRequest -Uri "$PlexUrl`:$PlexPort$($show.group.parentThumb | Select-Object -First 1)?X-Plex-Token=$plexToken" -OutVariable showPoster -ErrorAction Stop
$imgurLink = Invoke-ImgurUpload -ClientID $imgurCreds.UserName -ImageBase64 ([convert]::ToBase64String($showPoster.content)) -PlexPath $($show.group.parentThumb | Select-Object -First 1) -FilePath $ImgurFilePath -ErrorAction Stop
$tvList += "<tr><td><img src=`"$($imgurLink.ImgurLink)`" width=154px height=$(154/$($imgurLink.width)*$($imgurLink.height)) class=`"center`"></td>"
}
Catch {
Write-Verbose "Failed to get Imgur link for this show's poster. Exception: $($_.Exception.Message)"
$posterFail = $true
}
}
else {
if ($detailedResponse.poster_path) {
$tvList += "<tr><td><img src=`"https://image.tmdb.org/t/p/w154$($detailedResponse.poster_path)`" class=`"center`"></td>"
} else {
$posterFail = $true
}
}
# If the poster was unavailable, substitute a Plex logo
if ($posterFail) {$tvList += "<tr><td><img src=`"$imgPlex`" height=154px width=154px class=`"center`"></td>"}
$tvList += "<td><b><a href=`"http://www.imdb.com/title/$imdbID/`">$($show.name)</a></b> ($($detailedResponse.first_air_date.split('-')[0])-$($detailedResponse.last_air_date.split('-')[0]))"
$tvList += "<ul>"
if ($detailedResponse.genres) {$tvList += "<li><i>Genre:</i> $($detailedResponse.genres.name -join ", ")</li>"}
if ($contentRating) {$tvList += "<li><i>Rating:</i> $contentRating</li>"}
$tvList += "<li><i>Plot:</i> $($detailedResponse.overview)</li>"
$tvList += "<li><i>Now available:</i><br/></li><ul>"
foreach ($season in ($show.Group | Sort-Object @{e={$_.index -as [int]}})){
$tvList += "<li>$($season.title) - $($season.leafCount) episode$(if ($season.leafCount -gt 1){"s"})</li>"
}
}
else {
# If the series couldn't be found in the DB, fail gracefully
$tvList += "<tr><td><img src=`"$imgPlex`" height=150px width=150px class=`"center`"></td><td><li>$($show.name)</a></li>"
$tvList += "<td><li><a href=`"http://www.imdb.com/title/$($omdbResponse.imdbID)/`">$($show.name)</a></li>"
foreach ($season in $show.Group){
$tvList += "<ul><li>$($season.title) - $($season.leafCount) episode$(if ($season.leafCount -gt 1){"s"})</li>"
}
}
$tvList += "</ul></td></tr>"
Clear-Variable simpleResponse, detailedResponse, contentRating, imdbID, season
}
$tvList += "</table><br/>"
}
$collectionInfo = "<h2>Featured Collection:</h2><br/><table>"
if ($FeatureRandomCollection -or $FeatureSpecificCollection) {
$libraries = (Invoke-RestMethod "$PlexUrl`:$PlexPort/library/sections?X-Plex-Token=$plexToken").MediaContainer.Directory
$movieLibraries = $libraries | Where-Object {$_.type -eq 'movie' -and $_.title -notin $ExcludeLib}
$collections = @()
foreach ($library in $movieLibraries) {
$collections += (Invoke-RestMethod -Uri "$PlexUrl`:$PlexPort/library/sections/$($library.key)/all?type=18&context=content.collections&X-Plex-Token=$plexToken").MediaContainer.Directory
}
if ($collections) {
if ($FeatureSpecificCollection) {
Write-Verbose "A specific collection has been provided to feature. Looking for $FeatureSpecificCollection."
$collection = $collections | Where-Object {$_.title -eq $FeatureSpecificCollection}
}
# If the specific collection specified was not found, or none was provided, pick one at random.
if (-not $collection) {
$collection = $collections[(Get-Random -Minimum 0 -Maximum ($collections | Measure-Object).count)]
}
if ($UploadPostersToImgur) {
Invoke-WebRequest -Uri "$PlexUrl`:$PlexPort$($collection.thumb)?X-Plex-Token=$plexToken" -OutVariable collectionPoster
$imgurLink = Invoke-ImgurUpload -ClientID $imgurCreds.UserName -ImageBase64 ([convert]::ToBase64String($collectionPoster.content)) -PlexPath $collection.thumb -FilePath $ImgurFilePath
$collectionInfo += "<tr><td><img src=`"$($imgurLink.ImgurLink)`" width=154px height=$(154/$($imgurLink.width)*$($imgurLink.height)) class=`"center`"></td>"
}
else {
# If the poster wasn't uploaded, substitute a Plex logo
$collectionInfo += "<tr><td><img src=`"$imgPlex`" height=154px width=154px class=`"center`"></td>"
}
$collectionInfo += "<td><b>$($collection.title)</b> ($($collection.minYear)$(if ($collection.MaxYear -gt $collection.MinYear){" - $($collection.MaxYear)"}))"
$collectionInfo += "<ul>"
if ($collection.summary) {
$collectionInfo += "<li><i>Information:</i> $($collection.summary -replace '\n',' ')</li>"
}
$collectionInfo += "<li><i>Movie Count:</i> $($collection.childCount.ToString())</li>"
$collectionInfo += "<li><i>Last Updated:</i> $(Get-Date $epoch.AddSeconds($collection.updatedAt) -Format 'MMMM d')</li></ul></td></tr>"
$collectionInfo += "</table><br/>"
}
}
if (($movieCount -eq 0) -AND ($tvCount -eq 0)) {
$body = "$style`Sorry, but no movies or TV shows have been added to the Plex library in the past $days days. Check out the Featured Collection in the meantime!<br/><br/>"
if ($collection) {
$body += $collectionInfo -replace '\n','<br>'
}
} else {
$body = "$style`<h1>Hello!</h1><br/>Here's the list of additions to my Plex library in the past $days days.<br/>"
if ($movieCount -gt 0) {
Write-Verbose "Movie Count: $movieCount"
$body += $movieList -replace '\n','<br>'
}
if ($tvCount -gt 0) {
Write-Verbose "TV Count: $tvCount"
$body += $tvList -replace '\n','<br>'
}
if ($collection) {
Write-Verbose "Collection: $($collection.title)"
$body += $collectionInfo -replace '\n','<br>'
}
$body += "Enjoy!"
}
if (-not $OmitVersionNumber) {
$body += "<br><br><br><br><p align = right><font size = 1 color = Gray>Plex Version: $((Invoke-RestMethod "$PlexUrl`:$PlexPort/?X-Plex-Token=$plexToken" -Headers @{"accept"="application/json"}).mediaContainer.version). Posters/metadata from TMDb.</p></font>"
}
$body += "</body></html>"
$startDate = Get-Date (Get-Date).AddDays(-$days) -Format 'MMM d'
$endDate = Get-Date -Format 'MMM d'
# If not otherwise specified, set the To address the same as the From
if ($EmailTo -eq 'default') {
$EmailTo = $emailCreds.UserName
}
$subject = "Plex Additions from $startDate-$endDate"
if (-not($PreventSendingEmptyList -and (($movieCount+$tvCount) -eq 0))) {
Send-MailMessage -From $($emailCreds.UserName) -to $EmailTo -SmtpServer $SMTPserver -Port $SMTPport -UseSsl -Credential $emailCreds -Subject $subject -Body $body -BodyAsHtml -Encoding UTF8
Write-Verbose "Sent email to $EmailTo."
}
# Pop this if we're in Verbose mode to keep it up long enough to read output.
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
$response | Out-GridView
Write-Host 'Press any key to continue.'
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
}