forked from AndrewJNet/CopyMMSFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyMMS2016Files.ps1
50 lines (47 loc) · 2.16 KB
/
CopyMMS2016Files.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
##############################################
# #
# File: CopyMMS2016Files.ps1 #
# Author: Duncan Russell #
# http://www.sysadmintechnotes.com #
# Edited: Andrew Johnson #
# http://www.andrewj.net #
# #
##############################################
$baseLocation = 'C:\Conferences\MMS'
Clear-Host
$MMSDates='http://mms2016.sched.org/2016-05-16', 'http://mms2016.sched.org/2016-05-17', 'http://mms2016.sched.org/2016-05-18','http://mms2016.sched.org/2016-05-19'
ForEach ($Date in $MMSDates)
{
$uri = $Date
$sched = Invoke-WebRequest -Uri $uri -WebSession $mms
$links = $sched.Links
$links | ForEach-Object {
if(($PSItem.href -like '*event/*') -and ($PSItem.innerText -notlike '*birds*'))
{
$eventUrl = $PSItem.href
$eventTitle = $($PSItem.innerText -replace "full$", "") -replace "filling$", ""
"Checking session '{0}' for downloads" -f $eventTitle
$eventTitle = $eventTitle -replace "\W+", "_"
$uri = 'http://mms2016.sched.org'
$event = Invoke-WebRequest -Uri $($uri + $eventUrl)
$eventLinks = $event.Links
$eventLinks | ForEach-Object {
$eventFileUrl = $PSItem.href;$filename = $PSItem.href;if($eventFileUrl -like '*hosted_files*')
{
$downloadPath = $baseLocation + '\mms2016\' + $eventTitle
$filename = $filename.substring(39)
$filename = $filename.Replace('%20',' ')
$outputFilePath = $downloadPath + '\' + $filename
if((Test-Path -Path $($downloadPath)) -eq $false){New-Item -ItemType Directory -Force -Path $downloadPath | Out-Null}
if((Test-Path -Path $outputFilePath) -eq $false)
{
"...attempting to download '{0}'" -f $filename
Invoke-WebRequest -Uri $eventFileUrl -OutFile $outputfilepath -WebSession $mms;$doDownload=$false;
Unblock-File $outputFilePath
$stopit = $true
}
}
}
}
}
}