Skip to content

Instantly share code, notes, and snippets.

@Mukesh05
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mukesh05/2f3fb5a9bed173ec3549 to your computer and use it in GitHub Desktop.
Save Mukesh05/2f3fb5a9bed173ec3549 to your computer and use it in GitHub Desktop.
Use of WebClient Class
#Use of WebClient Class
$webClient = New-Object System.Net.WebClient
$webClient.DownloadString("http://www.telize.com/geoip")| ConvertFrom-Json | Select-Object longitude,latitude,country_code,timezone | Format-Table -AutoSize
#This is a simple function to wrap the above
$webClient = New-Object System.Net.WebClient
$url="http://www.telize.com/geoip"
function Get-GeoInformation
{
[CmdletBinding()]
param
(
[string]$url
)
try
{
$out=$webClient.DownloadString("$url")
$out
}
catch [Exception]
{
throw $_.Exception.Message
}
}
Get-GeoInformation $url| ConvertFrom-Json | Select-Object longitude,latitude,country_code,timezone |Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment