SharePoint Conference PPTs – Download them via PowerShell!

Here's the script to download the PPTs via PowerShell – the link to the file is below in case of copy paste errors!

function DownloadFile([string]$auth, [string] $file)
{
"Using " + $auth + " for file " + $file

$url = "http://www.mssharepointconference.com/sessionpresentations/" + $file
$file = "c:SPC11" + $file

$uri = new-object uri($url);
$httpReq = [system.net.HttpWebRequest]::Create($uri)
$httpReq.headers.add("Cookie", $auth)
$httpReq.Timeout = 75000
$httpReq.method = "GET"

$res = $httpReq.GetResponse()
$rs = $res.GetResponseStream();

$fs = new-object system.io.filestream($file, [System.IO.FileMode]::OpenOrCreate)
$read = new-object byte[] 1024

$count = $rs.Read($read, 0, $read.length)

while($count -ne 0)
{
$fs.write($read,0,$count)
$count = $rs.Read($read, 0, $read.length)
}

$fs.close()
$rs.Close()
$res.close()

}

function GetAuth([string] $username, [string]$password)
{
[system.net.servicepointmanager]::Expect100Continue = $false

#####################################
# Start session on SPConf site
####################################

$uri = new-object uri("http://www.mssharepointconference.com/Pages/Default.aspx");
$httpReq = [system.net.HttpWebRequest]::Create($uri)
$httpReq.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
$httpReq.ContentType = "application/x-www-form-urlencoded"
$httpReq.headers.Add("Accept-Language", "en-US")
$httpReq.method = "GET"

$res = $httpReq.GetResponse()
$rs = $res.GetResponseStream();
[System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs;
[string]$results = $sr.ReadToEnd();

#get the cookies
$strCookies = $res.Headers["set-cookie"].toString();                   
$res.Close();

$vnlehn = $strcookies

####################################
#  Do init post to live.com
####################################

$cookies = new-object system.net.CookieContainer
$uri = new-object uri("
https://login.live.com/wlogin.srf?appid=000000004C03DD21&alg=wsignin1.0&appctx=ConferenceVue");
$httpReq = [system.net.HttpWebRequest]::Create($uri)
$httpReq.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
$httpReq.Referer = "
http://www.mssharepointconference.com/Pages/Login.aspx?ReturnUrl=%2f_layouts%2fauthenticate.aspx%3fSource%3d%252FPages%252FDefault%252Easpx&Source=%2FPages%2FDefault%2Easpx"
$httpReq.ContentType = "application/x-www-form-urlencoded"
$httpReq.method = "GET"

$res = $httpReq.GetResponse()
$rs = $res.GetResponseStream();
[System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs;
[string]$results = $sr.ReadToEnd();

#get the cookies
$strCookies = $res.Headers["set-cookie"].toString();                   
$res.Close();

$mspr = $strCookies.substring(0, $strCookies.indexof(";")+1)
$mspok = $strCookies.substring($strCookies.indexof("MSPOK"))
$mspok = $mspok.substring(0, $mspok.indexof(";"))

$strCookies = $mspr + $mspok

#get random html values
$ppft = $results.remove(0, $results.indexof("PPFT"))
$ppft = $ppft.remove(0, $ppft.indexof("value") + 7)
$ppft = $ppft.substring(0, $ppft.indexof("`""))

$posturl = $results.remove(0, $results.indexof("g_QS=")+6)
$posturl = $posturl.substring(0, $posturl.indexof("`""))

####################################
#  Do the login
####################################

$uri = new-object uri("https://login.live.com/ppsecure/post.srf?" + $posturl)
$post = "login=" + $username + "&passwd=" + $password +"&type=11&LoginOptions=3&NewUser=1&MEST=&PPSX=Passport&PPFT=" + $ppft + "&idsbho=1&PwdPad=&sso=&i1=&i2=1&i3=4778&i4=&i12=1&i13=&i14=333&i15=334"
$encoding = new-object system.text.asciiencoding
$buf = $encoding.GetBytes($post)

$httpReq = [system.net.HttpWebRequest]::Create($uri)
$httpReq.method = "POST"
$httpReq.Referer = "
https://login.live.com/wlogin.srf?appid=000000004C03DD21&alg=wsignin1.0&appctx=ConferenceVue"
$httpReq.contentlength = $buf.length
$httpReq.Headers.add("Cookie", $strCookies)
$httpReq.ContentType = "application/x-www-form-urlencoded"
$stream = $httpReq.GetRequestStream()

[void]$stream.write($buf, 0, $buf.length)
$stream.close()

$res = $httpReq.GetResponse()
$rs = $res.GetResponseStream();
[System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs;
[string]$results = $sr.ReadToEnd();

$stoken = $results.remove(0, $results.indexof("id=`"stoken")+19)
$stoken = $stoken.substring(0, $stoken.indexof("`""))

####################################
#  Return token back to spconf site
####################################

$uri = new-object uri("http://www.mssharepointconference.com/_layouts/ConferenceVue/WindowsLive.aspx")
$post = "stoken=" + $stoken + "&appctx=ConferenceVue&action=login"

$encoding = new-object system.text.asciiencoding
$buf = $encoding.GetBytes($post)

$httpReq = [system.net.HttpWebRequest]::Create($uri)
$httpReq.method = "POST"
$httpReq.contentlength = $buf.length
$httpReq.ContentType = "application/x-www-form-urlencoded"
$httpReq.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, */*"
$httpReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; MS-RTC LM 8; LEN2)"
$httpReq.headers.Add("Cookie", $vnlehn + "; webauthtoken=")
$httpReq.headers.Add("Accept-Language", "en-US")
$httpReq.KeepAlive = $true
$httpReq.AllowAut
oRedirect = $false
$stream = $httpReq.GetRequestStream()

[void]$stream.write($buf, 0, $buf.length)
$stream.close()

$res = $httpReq.GetResponse()
$rs = $res.GetResponseStream();
[System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs;
[string]$results = $sr.ReadToEnd();

#get the cookie
$strCookies = $res.Headers["Set-Cookie"].toString();                   

#get the webauthtoken
if ($strcookies.contains("webauthtoken"))
{
$webauthtoken = $strCookies.substring($strCookies.indexof("webauthtoken"))
$webauthtoken = $webauthtoken.substring(0, $webauthtoken.indexof(";"))
}

#get the fedauth
if ($strcookies.contains("FedAuth"))
{
$fedauth = $strCookies.substring($strCookies.indexof("FedAuth"))
$fedauth = $fedauth.substring(0, $fedauth.indexof(";"))
}

return $vnlehn + ";" + $fedauth + ";" + $webauthtoken + ";"
}

######################################
#  Parse the HTML of the SPConf site
#####################################

#$results = get-content AllHtml.txt

#parse out the pptx links
#while($results.contains("SessionPresentations"))
#{
#$results = $results.remove(0, $results.indexof("SessionPresentations/")+21)
#$filename = $results.substring(0, $results.indexof("pptx") + 4)
#$results = $results.remove(0, $results.indexof("pptx")+4)

#$filename

#add-content "c: empppts.txt" $filename
#}

##############################
#  Start program
###############################

[System.Reflection.Assembly]::LoadWithPartialName( "System.Web" ) | out-null
[System.Reflection.Assembly]::LoadWithPartialName( "System.Net" ) | out-null

$username = read-host "Enter your LiveID username: "
$password = read-host "Enter your LiveID password: "

$auth = GetAuth $username $password

while(-not $auth.tostring().contains("webauthtoken"))
{
$auth = GetAuth $username $password
}

############################
# Download all the PPTs
###############################

#use for testing in case you NEVER get the webauthtoken back…
#$auth = ""

$ppts = get-content "c:ppts.txt"
mkdir "c:spc11"

foreach($line in $ppts)
{
DownloadFile $auth $line

}

Here's all the PPTX files on the site (Place in a files called c:ppts.txt):

SPC216.pptx
SPC340.pptx
SPC102.pptx
SPC2991.pptx
SPC214.pptx
SPC240.pptx
SPC367.pptx
SPC2994.pptx
SPC249.pptx
SPC263.pptx
SPC253.pptx
SPC256.pptx
SPC274.pptx
SPC285.pptx
SPC202.pptx
SPC225.pptx
SPC345.pptx
SPC228.pptx
SPC350.pptx
SPC104.pptx
SPC229_Mercaldo.pptx
SPC387.pptx
SPC2992.pptx
SPC410.pptx
SPC376.pptx
SPC258.pptx
SPC265.pptx
SPC273.pptx
SPC201.pptx
SPC311.pptx
SPC403.pptx
SPC335.pptx
SPC406.pptx
SPC226.pptx
SPC358.pptx
SPC359.pptx
SPC245.pptx
SPC246.pptx
SPC262.pptx
SPC221.pptx
SPC200.pptx
SPC330.pptx
SPC346.pptx
SPC347.pptx
SPC351.pptx
SPC239.pptx
SPC242.pptx
SPC371.pptx
SPC252.pptx
SPC109.pptx
SPC254.pptx
SPC255.pptx
SPC382.pptx
SPC266.pptx
SPC271.pptx
SPC3995.pptx
SPC224.pptx
SPC310.pptx
SPC223.pptx
SPC298.pptx
SPC244.pptx
SPC366.pptx
SPC212.pptx
SPC264.pptx
SPC108_Barnard.pptx
SPC391.pptx
SPC280.pptx
SPC3992.pptx
SPC269.pptx
SPC289.pptx
SPC292.pptx
SPC215.pptx
SPC219.pptx
SPC338.pptx
SPC343.pptx
SPC234.pptx
SPC352.pptx
SPC103.pptx
SPC357.pptx
SPC248.pptx
SPC398.pptx
SPC288.pptx
SPC251.pptx
SPC306.pptx
SPC307.pptx
SPC204.pptx
SPC322.pptx
SPC206.pptx
SPC207.pptx
SPC2993.pptx
SPC348.pptx
SPC409_Kogan.pptx
SPC243.pptx
SPC368.pptx
SPC375.pptx
SPC383.pptx
SPC388.pptx
SPC275-1.pptx
SPC281.pptx
SPC3996.pptx
SPC293.pptx
SPC314.pptx
SPC213.pptx
SPC331.pptx
SPC401.pptx
SPC220.pptx
SPC222.pptx
SPC336.pptx
SPC3982.pptx
SPC397.pptx
SPC260.pptx
SPC261.pptx
SPC279.pptx
SPC291.pptx
SPC400_1.pptx
SPC203.pptx
SPC315_1.pptx
SPC342.pptx
SPC257.pptx
SPC259.pptx
SPC299.pptx
SPC365_1.pptx
SPC373_1.pptx
SPC377.pptx
SPC272.pptx
SPC389_1.pptx
SPC250.pptx
SPC278.pptx
SPC290.pptx
SPC304_A.pptx
SPC319_A.pptx
SPC287.pptx
SPC321_1.pptx
SPC296.pptx
SPC356_1.pptx
SPC374_1.pptx
SPC386_1.pptx
SPC270.pptx
SPC392_f.pptx
SPC414.pptx
SPC3999.pptx
SPC309_1.pptx
SPC328.pptx
SPC333_1.pptx
SPC339_1.pptx
SPC341.pptx
SPC407.pptx
SPC349_1.pptx
SPC237.pptx
SPC355_1.pptx
SPC360_1.pptx
SPC354_1.pptx
SPC379_1.pptx
SPC101.pptx
SPC396.pptx
SPC282.pptx
SPC410r.pptx
SPC308.pptx
SPC313_1.pptx
SPC205.pptx
SPC318.pptx
SPC210.pptx
SPC230.pptx
SPC233.pptx
SPC295.pptx
SPC236.pptx
SPC268.pptx
SPC369_1.pptx
SPC380_1.pptx
SPC384_1.pptx
SPC412_1.pptx
SPC266r.pptx
SPC241.ppt
SPC326.pptx
SPC329_1.pptx
SPC217.pptx
SPC218.pptx
SPC402_1.pptx
SPC404_1.pptx
SPC337_1.pptx
SPC408_1.pptx
SPC232_1.pptx
SPC378_1.pptx
SPC385_1.pptx
SPC300.pptx
SPC302.pptx
SPC344.pptx
SPC320.pptx
SPC362.pptx
SPC324.pptx
SPC327.pptx
SPC332.pptx
SPC334.pptx
SPC227.pptx
SPC277.pptx
SPC283.pptx
SPC413.pptx
SPC294.pptx
SPC3983.pptx
SPC267.pptx
SPC247.pptx
SPC361.pptx
SPC364.pptx
SPC393.pptx
SPC394.pptx
SPC395.pptx
SPC3993.pptx
SPC297.pptx
SPC303.pptx
SPC353.pptx
SPC2995.pptx
SPC372.pptx
SPC323.pptx
SPC411.pptx
SPC399.pptx
SPC3994.pptx

SPC221.pptx
SPC235.pptx
SPC276.pptx
SPC286.pptx
SPC312_1.pptx
SPC316_1.pptx
SPC363.pptx
SPC370.pptx
SPC381_a.pptx
SPC3991_1.pptx
SPC3997_Maio.pptx

Enjoy!
Chris