Issue in downloading file from web url

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ankit Parmar Ankit Parmar 10 months, 1 week ago.

  • Author
    Posts
  • #34358
    Profile photo of Ankit Parmar
    Ankit Parmar
    Participant

    Hi,

    I made a script in which i am downloading a software from a url and made the whole environment for that in script but it is not running. Here is the script –

    $url = "http://nuget.org/nuget.exe"
    $output = "$PSScriptRoot\nuget.exe"
    $start_time = Get-Date
    $downloadpath = "C:\Users\ankitpar\Downloads"
    Invoke-WebRequest -Uri $url -OutFile $output Set-Location $downloadpath
    Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

    Error given on execution is –

    Invoke-WebRequest :
    A positional parameter cannot be found that accepts argument 'Set-Location'.
    At line:4 char:1
    + Invoke-WebRequest -Uri $url -OutFile $output Set-Location C:

  • #34359
    Profile photo of Vincent Karunaidas
    Vincent Karunaidas
    Participant

    $url = "http://nuget.org/nuget.exe"
    $start_time = Get-Date
    $downloadpath = "C:\Users\Vincent\Downloads\Nuget.exe"
    Invoke-WebRequest -Uri $url -OutFile $downloadpath
    Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"

    If you want to save the file where script is located
    $downloadpath = "$PSScriptRoot\nuget.exe"

  • #34360
    Profile photo of Ankit Parmar
    Ankit Parmar
    Participant

    thanks Vincent.. its work...

You must be logged in to reply to this topic.