breath
April 15, 2020, 8:09am
1
Hi all, I’m new in PowerShell. I’m trying to create a script where I download an exe file.
I found some example from internet and I wrote it, but when I execute my script I receive the following error:
Invoke-WebRequest : Could not find a part of the path 'C:\Users\xxxxxx\Downloads\SW\Download'.
At line:1 char:1
Invoke-WebRequest -Uri $url -OutFile $output
CategoryInfo : NotSpecified: ( [Invoke-WebRequest], DirectoryNotFoundException
FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Could you help me please to understand the error?
Olaf
April 15, 2020, 8:16am
2
Antonella, welcome to Powershell.org . Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did! .
When you post code or error messages or sample data or console output format it as code using the code tags “PRE ”, please. Thanks in advance.
It looks like you did not specify a file not just a directory for your parameter -OutFile .
breath
April 15, 2020, 8:25am
3
Thanks,
I haven’t wrote all the script… I write it:
$output = "C:\Users\xxxxxxx\Downloads\SW\Download\"
$url = "https://www.google.com/chrome/"
Invoke-WebRequest -Uri $url -OutFile $output
The output I received
Invoke-WebRequest : Could not find a part of the path ‘C:\Users\xxxxxx\Downloads\SW\Download\’.
At line:1 char:1
+ Invoke-WebRequest -Uri $url -OutFile $output
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Olaf
April 15, 2020, 8:28am
4
I assume it is a setup file you try to download. You should use something like this:
$output = "C:\Users\xxxxxxx\Downloads\SW\Download\setup.exe"
It should be a complete path including the file name.
breath
April 15, 2020, 8:33am
5
Oh Thanks a lot.
It works! I thought I haven’t to write the exe file name.
Thanks a lot again.