This has been updated to Version 2, see: http://www.cosonok.com/2017/07/netapp-technical-report-tr-powershell_30.html
Taking inspiration from Eric Ligman's Free Microsoft eBook Script...
Taking inspiration from Eric Ligman's Free Microsoft eBook Script...
Run the attached script to download all the TRs (at least
TRs called TR-XXXX.pdf). If the TR has already been downloaded to the download
folder, the program checks if you’ve got the latest version, and if you’ve not
got the latest it updates.
There’s 3 switches you can specify values for it you want
(but you don’t need to). I’ve preset them as below:
[Int]$RangeStart
= 4000,
[Int]$RangeEnd = 5000,
[String]$DownloadFolder
= "C:\Downloads\NetAppTRs\"
That’s probably way too many TRs to be honest. TR-4000 is
“SnapDrive 6.5 for Windows for Clustered Data ONTAP: Best Practices Guide”. And
the latest TR at the time of writing is TR-4612 “NetApp SolidFire and Dataos IO
RecoverX with Cassandra.” With the values specified above, the total download
size comes to around 665MB.
The only problem is that they’re saved as TR-XXXX.pdf, so
without opening them up you won’t have a scooby what they’re all about. I will
post an index in the next post.
The Script
Copy and paste into
a text editor and save as say NetAppTR_Collector.ps1. The run in PowerShell
with>
.\NetAppTR_Collector.ps1
##
NetAppTR_Collector.ps1
#
This program will collect all the TRs from:
#
https://www.netapp.com/us/media/tr-XXXX.pdf
#
Where XXXX is specified by $RangeStart to $RangeEnd
Param(
[Int]$RangeStart = 4000,
[Int]$RangeEnd = 5000,
[String]$DownloadFolder =
"C:\Downloads\NetAppTRs\"
)
Function
Wr{Param($P,$I="WHITE");Write-Host $P -ForegroundColor $I}
##
Download Folder and Dead Links Log ##
[Void](New-Item
-ItemType Directory -Force -Path $DownloadFolder)
If(Test-Path
$DownloadFolder){}
else{
Wr "FAILED: Test-Path
$DownloadFolder" RED;Pause;EXIT
}
If($DownloadFolder
-match '.+?\\$'){}
else{
$DownloadFolder += "\"
}
If(Test-Path
($DownloadFolder + "dead_links.log")){
Copy-Item ($DownloadFolder +
"dead_links.log") ($DownloadFolder + "dead_links.log.bak")
}else{
[Void](New-Item c:\scripts\new_file.txt
-type file -force)
}
##
Download the TRs ##
Import-Module
BitsTransfer
for($i=$RangeStart;
$i -le $RangeEnd; $i++){
$Title = "tr-$i"
$WebUrl =
"https://www.netapp.com/us/media/$Title.pdf"
$SavePath = ($DownloadFolder +
"$Title.pdf")
## Get the header ##
$hdr = $NULL
try{$hdr = Invoke-WebRequest $WebUrl -Method
Head}
catch{$WebUrl | Out-File ($DownloadFolder +
"dead_links.log") -Append}
If($hdr){
## Only Download Updated Versions ##
$Download = $FALSE
If(Test-Path $SavePath){
$SavedLRT = [DateTime]((Get-ChildItem
$SavePath).LastWriteTime)
$WebFileLRT = [DateTime]($hdr.headers."last-modified")
If($WebFileLRT.Ticks -gt
$SavedLRT.Ticks){
Wr "UPDATED : $Title" GREEN
$Download = $TRUE
}else{
Wr "NO UPD. : $Title"
}
}else{
Wr "NEW D/LOAD: $Title" GREEN
$Download = $TRUE
}
## Download ##
If($Download){
Start-BitsTransfer
-Source $WebUrl -Destination $SavePath
}
}else{
Wr "DEAD LINK : $WebUrl"
}
}
Image:
NetAppTR_Collector.PS1 in Action!
Comments
Post a Comment