Friday, 28 July 2017

NetApp Technical Report (TR) PowerShell Collector 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
# This program will collect all the TRs from:
# Where XXXX is specified by $RangeStart to $RangeEnd

  [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){}
        Wr "FAILED: Test-Path $DownloadFolder" RED;Pause;EXIT
If($DownloadFolder -match '.+?\\$'){}
        $DownloadFolder += "\"
If(Test-Path ($DownloadFolder + "dead_links.log")){
        Copy-Item ($DownloadFolder + "dead_links.log") ($DownloadFolder + "dead_links.log.bak")
        [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 = "$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}


    ## 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
        Wr "NO UPD.   : $Title"
      Wr "NEW D/LOAD: $Title" GREEN
      $Download = $TRUE

    ## Download ##
        Start-BitsTransfer -Source $WebUrl -Destination $SavePath

    Wr "DEAD LINK : $WebUrl"

Image: NetAppTR_Collector.PS1 in Action!

No comments:

Post a Comment