More so Totally Off Topic

Started by stanl, January 25, 2019, 04:50:57 AM

Previous topic - Next topic

stanl

As there have been several recent posts concerning Powershell and WB, below is a script that will automagically downloads PS cheatsheets to a directory of your PC.  My interest is not so much in the content [which is great] but the speed of the download. It uses BITS and I wonder if WB can natively handle that transfer method. [or this has already been asked and I missed it]




# enable SSL download
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

# download page
$url = "https://github.com/PrateekKumarSingh/CheatSheets/tree/master/Powershell"
$page = Invoke-WebRequest -UseBasicParsing -Uri $url
$links = $page.Links |
   Where-Object { $_.href -like '*.pdf' } |
   Select-Object -Property title, href |
   # turn URLs into directly downloadable absolute URLs
   ForEach-Object {
       $_.href = 'https://github.com/PrateekKumarSingh/CheatSheets/raw/master/Powershell/' + $_.title
       $_
   }

# create folder on your desktop
$Path = "$home\Desktop\CheatSheets"
$exists = Test-Path -Path $Path
if (!$exists) { $null = New-Item -Path $path -ItemType Directory }

# download cheat sheets
$links | ForEach-Object {
   $docPath = Join-Path -Path $Path -ChildPath $_.Title
   Start-BitsTransfer -Source $_.href -Destination $docPath -Description $_.title
   # alternate way of downloading
   # Invoke-WebRequest -UseBasicParsing -Uri $_.href -OutFile $docPath
}

# open folder
explorer $Path