Author Posts

January 27, 2016 at 1:03 am

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:

January 27, 2016 at 1:26 am

$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"

January 27, 2016 at 2:03 am

thanks Vincent.. its work...