From 361ce147eb1bc6d7546303381163eeb5f7139d27 Mon Sep 17 00:00:00 2001 From: eeckert Date: Thu, 10 Aug 2023 13:19:12 -0600 Subject: [PATCH] Fixed code - V1.0! --- Download-SnapperReports.ps1 | 40 ++++++++++++------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/Download-SnapperReports.ps1 b/Download-SnapperReports.ps1 index c9075ea..1ed20fd 100644 --- a/Download-SnapperReports.ps1 +++ b/Download-SnapperReports.ps1 @@ -26,42 +26,28 @@ do { Write-Debug -Message ("Processing: $project_Name") -Debug - # $project.visits | foreach -Parallel { - # $pathExist = Test-Path $USING:OutputPathBase_Project -ErrorAction SilentlyContinue - # if (!($pathExist)) { - # New-Item -Path $USING:OutputPathBase_Project -ItemType Directory - # } - # if ($_) { - # $testURI = $_.pdf_link + '&auth_token=' + $USING:APIToken - # $Outfile = $USING:OutputPathBase_Project + '\' + $_.unique_id + ".pdf" - # Invoke-WebRequest -Uri $testURI -OutFile $Outfile -TimeoutSec 300 - # } - # } -ThrottleLimit 5 - - foreach ($visit in $Project.visits) { - $pathExist = Test-Path $OutputPathBase_Project -ErrorAction SilentlyContinue + $project.visits | foreach -Parallel { + $pathExist = Test-Path $USING:OutputPathBase_Project -ErrorAction SilentlyContinue if (!($pathExist)) { - New-Item -Path $OutputPathBase_Project -ItemType Directory + New-Item -Path $USING:OutputPathBase_Project -ItemType Directory } - if ($visit) { - Write-Debug -Message ("Checking " + $visit.unique_id) -Debug - $testURI = $visit.pdf_link + '&auth_token=' + $APIToken - $Outfile = $OutputPathBase_Project + '\' + $visit.unique_id + ".pdf" + if ($_) { + Write-Debug -Message ("Checking " + $_.unique_id) -Debug + $testURI = $_.pdf_link + '&auth_token=' + $USING:APIToken + $Outfile = $USING:OutputPathBase_Project + '\' + $_.unique_id + ".pdf" if (!(Test-Path $Outfile)) { - Write-Debug ("Saving file: "+ $Outfile) -Debug + Write-Debug ("Saving file: " + $Outfile) -Debug Invoke-WebRequest -Uri $testURI -OutFile $Outfile } - } - } - $page++ + } -ThrottleLimit 5 } - + $page++ +} - -} until ( - $response.Content -eq $null +until ( + $null -eq $response.Content )