Download a Web Page with Windows PowerShell

This is an example of using Windows PowerShell to download a Web page and print it to the screen.
$url = "http://www.ke5prl.com"
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents

Now while that might be a neat use of technology it is not terribly useful. If we modify the code just a little we can get back callsign information from one of the common Web lookups. For our first modification let’s change the first line to
$url = "http://www.arrl.org/fcc/fcclook.php3?call=ke5prl" and you can substitute your callsign for mine.

Now let’s turn this into a function. By making it into a function we can easily pass different callsigns to the function without changing the code.
function callsign($call){
$url = "http://www.arrl.org/fcc/fcclook.php3?call=" + $call
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents
}
callsign("KE5PRL")

Leave a comment