I am trying to write a powershell script that will set a download directory variable based on the current directory, and download a file to that directory.
The code I have is:
cd downloads
$DevDownloadDirectory = [IO.Directory]::GetCurrentDirectory
$clnt = New-Object System.Net.WebClient
# download and extract the file
$url = “fileurl/file.zip"
$file = "$DevDownloadDirectory\file.zip"
$clnt.DownloadFile($url,$file)
The problem I get is whenever I get to this part of the code it pumps out:
Exception calling “DownloadFile” with “2” argument(s): “An exception
occurred during a WebClient request.” At C:\directory\script.ps1:462
char:20
- $clnt.DownloadFile <<<< ($url,$file)
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : DotNetMethodException
Could anyone please help me figure out why this is happening?
Should be
GetCurrentDirectory() is a Method and if you dont use the “()”, it will just return the same name but not the current directory.