tomkandy

u/tomkandy



r/PowerShell•
function Get-Weather
{
    param
    (
        [Parameter(Position=0, Mandatory=$false, ValueFromPipelineByPropertyName=$true)][Alias('latitude')]$lat,
        [Parameter(Position=1, Mandatory=$false, ValueFromPipelineByPropertyName=$true)][Alias('longitude')]$long,
        [Parameter(Position=2, Mandatory=$false, ValueFromPipelineByPropertyName=$true)][Alias('city')]$cityName
    )
    begin{$webclient = New-Object System.Net.webclient}
    process
    {
        if ($lat -ne $null -and $long -ne $null)
        {
            $url = "http://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$long&mode=xml&units=metric"
459

r/PowerShell•
function Get-GeoIP
{
    param($ip)
    
    $webclient = New-Object System.Net.webclient
    $providerRoot = "http://freegeoip.net/xml/"
    [xml]$geoData = $webclient.downloadstring($providerRoot+$ip)
    Write-Output $geoData.response
}

Usage example;

PS C:\Users\tom> Get-GeoIP 6.7.8.9

Ip          : 6.7.8.9
CountryCode : US
CountryName : United States
RegionCode  : AZ
RegionName  : Arizona
City        : Fort Huachuca
ZipCode     : 85613
Latitude    : 31.5273
Longitude   : -110.3607
MetroCode   : 789
AreaCode    : 520

Output is an object, so we can do fun things like

PS C:\Users\tom> 
4312