Forum Discussion
CS_HelpDesk
2 years agoGoTo Contributor
Downloads file from a given URL to the working directory or to a specified folder.
$url = $null
$destination = 'C:\DistributedFiles'
$fileName = $null
$outFile = $fileName;
if (-Not $outFile)
{
$outFile = $url.Split('/')[-1];
$outFile = $outFile.Split('?')[0];
}
If (-Not (Test-Path -Path $destination -PathType Container))
{
New-Item -Path $destination -ItemType Container
}
$outPath = Join-Path -Path $destination -ChildPath $outFile
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $outPath)