PoshCode Logo PowerShell Code Repository

Get-WebFile 1.0 by Joel Bennett 4 years ago
View followups from Joel Bennett | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/121"></script>download | new post

The simplest form of WGet … no options, no passwords, no nothing. But it works.

  1. # ---------------------------------------------------------------------------
  2. ### <Script>
  3. ### <Author>
  4. ### Joel "Jaykul" Bennett
  5. ### </Author>
  6. ### <Description>
  7. ### Downloads a file from the web to the specified file path.
  8. ### </Description>
  9. ### <Usage>
  10. ### Get-URL http://huddledmasses.org/downloads/RunOnlyOne.exe RunOnlyOne.exe
  11. ### Get-URL http://huddledmasses.org/downloads/RunOnlyOne.exe C:\Users\Joel\Documents\WindowsPowershell\RunOnlyOne.exe
  12. ### </Usage>
  13. ### </Script>
  14. # ---------------------------------------------------------------------------
  15. param([string]$url, [string]$path)
  16.  
  17. if(!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path))) {
  18.   $path = Join-Path $pwd (Split-Path -leaf $path)
  19. }
  20.  
  21. "Downloading [$url]`nSaving at [$path]"
  22. $client = new-object System.Net.WebClient
  23. $client.DownloadFile( $url, $path )
  24.  
  25. $path

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me