March 4, 2010

Powershell: WGet as Get-WebPage

Filed under: Script — Tags: — Kevmar @ 5:10 am

WGet is an old favorite of mine.  It is very easy to replicate in powerhshell by calling out to the system.web.WebClient object.

function Get-WebPage{
  Process {
   if($_ -ne $null){
      Write-Output (new-object system.net.WebClient).DownloadString($_)
    }
    elseif ($args[0] -ne $null){
      Write-Output (new-object system.net.WebClient).DownloadString($args[0])
    }
  }
}

Get-WebPage "http://www.ithinkincode.com"

All this gives you is the raw text of the page. You can then pipe it into a file or into another function.

Powered by WordPress