Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan1el42/57855af4fe33485e63672a3c41644ad0 to your computer and use it in GitHub Desktop.
Save Dan1el42/57855af4fe33485e63672a3c41644ad0 to your computer and use it in GitHub Desktop.
Import-Module BitsTransfer
$Uri = 'http://download.nai.com/products/licensed/superdat/nai/Brazilian'
$DestinationPath = 'D:\Temp'
$Response = Invoke-WebRequest -UseBasicParsing -Uri $Uri
if ($Response.StatusCode -eq 200) {
$Matches = [regex]::Matches($Response.RawContent, '(\d+xdat\.exe)"')
if ($Matches.Count -ge 1)
{
$LastMatch = $Matches[$Matches.Count - 1]
$FileName = $LastMatch.Groups[$LastMatch.Groups.Count - 1]
$Source = "${Uri}/${FileName}"
$Destination = Join-Path -Path $DestinationPath -ChildPath $FileName
$Job = Start-BitsTransfer -Source $Source -Destination $Destination -Asynchronous
Do
{
$Percentage = [int](($Job.BytesTransferred*100) / $Job.BytesTotal)
Write-Progress -Activity "Downloading file..." -CurrentOperation "${Percentage}% complete"
Start-Sleep -Seconds 1
} While ($Job.JobState -in 'Connecting', 'Transferring')
Complete-BitsTransfer -BitsJob $Job
"Definition file downloaded to ${Destination}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment