Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Refrence material:
- ##https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/split-path?view=powershell-7.2
- ##https://lazyadmin.nl/powershell/download-file-powershell/
- ##https://shellgeek.com/powershell-create-directory-if-not-exists/
- ##https://4sysops.com/archives/use-powershell-to-download-a-file-with-http-https-and-ftp/
- #Set destination to download file too.
- $destination = "c:\temp\downloads"
- #Ask tech where to download from.
- $source = "ServerUtilsAskTech (URL,text,http://test)"
- #Check if destination exists. If not create it.
- if (Test-Path $destination) {
- Write-Host "Folder Exists"
- }
- else
- {
- #PowerShell Create directory if not exists
- New-Item $destination -ItemType Directory
- Write-Host "Folder Created successfully"
- }
- #get file name from download url
- $destination = $destination + $(Split-Path -Path $source -Leaf)
- #Invoke-WebRequest -Uri $source -OutFile $destination
- Import-Module BitsTransfer
- $Job = Start-BitsTransfer -Source $source -Destination $destination -Asynchronous -Priority normal -TransferType Download
- echo "Running Job"
- while (($Job.JobState -eq "Transferring") -or ($Job.JobState -eq "Connecting")) `
- { sleep 5;} # Poll for status, sleep for 5 seconds, or perform an action.
- echo "completing job"
- echo $Job
- Switch($Job.JobState)
- {
- "Transferred" {Complete-BitsTransfer -BitsJob $Job}
- "Error" {$Job | Format-List } # List the errors.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement