8/20/2015

Using PowerShell to Pull .ppt Files off the Web

I was perusing the web looking for free online training on Data Mining.

Found a course on the site: http://www.kdnuggets.com/data_mining_course/index.html

The instructions say to prefix the URL and then append the suffix.


So I proceeded to copy-paste the list into Excel:


Copy-Pasted the results to a new tab:


Found a site with example script to pull files using PowerShell: https://blog.jourdant.me/3-ways-to-download-files-with-powershell/

Copied and modified script to the following:



Opened PowerShell ISE as Administrator, changed directory path to the folder containing the script, loaded in PowerShell ISE and ran the following command:

Set-ExecutionPolicy RemoteSigned

Then ran just file #9:


PowerShell Script file:


I'm sure there's a way to loop through all 19 files, and read from Excel, but instead, I just copied and pasted the code 18 times, modified:



Execute Script.ps1:



$url = "http://www.kdnuggets.com/data_mining_course/dm8-decision-tree-cart.ppt"
$output = "$PSScriptRoot\dm8-decision-tree-cart.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm7-decision-tree-c45.ppt"
$output = "$PSScriptRoot\dm7-decision-tree-c45.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm6-decision-tree-intro.ppt"
$output = "$PSScriptRoot\dm6-decision-tree-intro.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm5-classification-basic.ppt"
$output = "$PSScriptRoot\dm5-classification-basic.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm4-output-representation.ppt"
$output = "$PSScriptRoot\dm4-output-representation.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm3-input-concepts.ppt"
$output = "$PSScriptRoot\dm3-input-concepts.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm2-intro-machine-learning-classification.ppt"
$output = "$PSScriptRoot\dm2-intro-machine-learning-classification.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm1-introduction-ml-data-mining.ppt"
$output = "$PSScriptRoot\dm1-introduction-ml-data-mining.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm19-data-mining-and-society.ppt"
$output = "$PSScriptRoot\dm19-data-mining-and-society.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm18-microarray-data-mining.ppt"
$output = "$PSScriptRoot\dm18-microarray-data-mining.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm17-targeted-marketing-kdd-cup.ppt"
$output = "$PSScriptRoot\dm17-targeted-marketing-kdd-cup.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm16-summarization-deviation-detection.ppt"
$output = "$PSScriptRoot\dm16-summarization-deviation-detection.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm15-rules-regression-knn.ppt"
$output = "$PSScriptRoot\dm15-rules-regression-knn.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm16-rules-regression-knn.ppt"
$output = "$PSScriptRoot\dm16-rules-regression-knn.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm14-association-rules.ppt"
$output = "$PSScriptRoot\dm14-association-rules.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm13-clustering.ppt"
$output = "$PSScriptRoot\dm13-clustering.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm12-data-preparation.ppt"
$output = "$PSScriptRoot\dm12-data-preparation.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm11-evaluation-lift-cost.ppt"
$output = "$PSScriptRoot\dm11-evaluation-lift-cost.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm10-evaluation.ppt"
$output = "$PSScriptRoot\dm10-evaluation.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

$url = "http://www.kdnuggets.com/data_mining_course/dm9-rules-regression-knn.ppt"
$output = "$PSScriptRoot\dm9-rules-regression-knn.ppt"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" 


Files #5 and #8 weren't found, other than that, all files downloaded fine:


That's a basic example of how to pull files off the web using PowerShell ISE.  PowerShell is completely flexible and there's so much you can do with it.  The one thing I remember from watching some online courses, use the "help files".

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.