<#
.SYNOPSIS
return your public IP address
.DESCRIPTION
queries the ipify public IP address API and returns your public IP
.EXAMPLE
get-PublicIP
returns the public IP
.OUTPUTS
system.string
.NOTES
https://github.com/rdegges/ipify-api
#>
function Get-PublicIP {
[CmdletBinding()]
param (
)
$uri = 'https://api.ipify.org'
try {
$invokeRestMethodSplat = @{
Uri = $uri
ErrorAction = 'Stop'
}
$publicIp = Invoke-RestMethod @invokeRestMethodSplat
}
catch {
Write-Error $_
}
return $publicIp
}
PS C:\Users\bob> get-publicIP -verbose
VERBOSE: GET https://api.ipify.org/ with 0-byte payload
VERBOSE: received 13-byte response of content type text/plain
VERBOSE: Content encoding: iso-8859-1
68.145.44.229
PS C:\Users\bob> function Get-Weather {
>> [CmdletBinding()]
>> param (
>> [Parameter(
>> Position = 0,
>> Mandatory = $false
>> )]
>> [string]
>> $City,
>>
>> [Parameter(Position = 1)]
>> [ValidateSet('Metric', 'USCS')]
>> [string]
>> $Units = 'USCS',
>>
>> [Parameter(Position = 2)]
>> [ValidateSet('ar', 'af', 'be', 'ca', 'da', 'de', 'el', 'en', 'et', 'fr', 'fa', 'hu', 'ia', 'id', 'it', 'nb', 'nl', 'pl', 'pt-br', 'ro', 'ru', 'tr', 'th', 'uk', 'vi', 'zh-cn', 'zh-tw')]
>> [string]
>> $Language = 'en',
>>
>> [Parameter(Position = 3)]
>> [switch]
>> $Short
>> )
>>
>> $uriString = 'https://wttr.in/'
>>
>> if ($City) {
>> $uriString += "$City"
>> }
>>
>> switch ($Units) {
>> 'Metric' {
>> $uriString += "?m"
>> }
>> 'USCS' {
>> $uriString += "?u"
>> }
>> }
>>
>> if ($Short) {
>> $uriString += "&format=4"
>> }
>>
>> $uriString += "&lang=$Language"
>>
>> Write-Verbose "URI: $uriString"
>>
>> $invokeSplat = @{
>> Uri = $uriString
>> ErrorAction = 'Stop'
>> }
>>
>> try {
>> Invoke-RestMethod @invokeSplat
>> }
>> catch {
>> Write-Error $_
>> }
>> }#Get-Weather
PS C:\Users\bob> get-weather
Weather report: Calgary, Canada
\ / Partly cloudy
_ /"".-. 44..50 °F
\_( ). ↓ 18 mph
/(___(__) 9 mi
0.0 in
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Wed 12 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │
│ _ /"".-. 46..51 °F │ _ /"".-. 55..59 °F │ _ /"".-. 62 °F │ _ /"".-. 59 °F │
│ \_( ). ↘ 16-18 mph │ \_( ). ↓ 13-14 mph │ \_( ). ← 9-11 mph │ \_( ). ← 8-16 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Thu 13 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │
│ _ /"".-. 55..57 °F │ _ /"".-. 66 °F │ _ /"".-. 68 °F │ _ /"".-. 60 °F │
│ \_( ). → 2-3 mph │ \_( ). ↖ 5-6 mph │ \_( ). ↖ 9-12 mph │ \_( ). ↖ 7-14 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Fri 14 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │
│ _ /"".-. 53 °F │ _ /"".-. 66 °F │ _ /"".-. 64 °F │ _ /"".-. 62 °F │
│ \_( ). ↘ 3-4 mph │ \_( ). ↖ 3 mph │ \_( ). ↖ 5-6 mph │ \_( ). ↙ 4-8 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Follow @igor_chubin for wttr.in updates
get-help get-weather -showwindow
Synopsis
Get-Weather [[-City] <string>] [[-Units] <string>] [[-Language] <string>] [-Short] [<CommonParameters>]
Parameters
-City <string>
Required? false
Position? 0
Default value
Accept pipeline input? false
Accept wildcard characters?
-Language <string>
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters?
-Short <>
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters?
-Units <string>
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters?
Syntax
Get-Weather [[-City] <string>] [[-Units] <string>] [[-Language] <string>] [[-Short] ] [<CommonParameters>]
Inputs
None
Outputs
System.Object
Remarks
None
PS C:\Users\bob> get-weather -city 'toronto'
Weather report: toronto
\ / Sunny
.-. 64 °F
― ( ) ― ↗ 3 mph
`-’ 8 mi
/ \ 0.0 in
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Wed 12 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Clear │
│ _ /"".-. 77..78 °F │ _ /"".-. 84 °F │ _ /"".-. 86..87 °F │ .-. 84..86 °F │
│ \_( ). → 3-4 mph │ \_( ). ↑ 3 mph │ \_( ). ↗ 2-3 mph │ ― ( ) ― ↑ 2 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │ `-’ 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │ / \ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Thu 13 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Sunny │ \ / Partly cloudy │
│ _ /"".-. 75..77 °F │ _ /"".-. 80 °F │ .-. 80..82 °F │ _ /"".-. 78..80 °F │
│ \_( ). ↙ 5-6 mph │ \_( ). ← 5-6 mph │ ― ( ) ― ← 9-10 mph │ \_( ). ← 8-10 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ `-’ 6 mi │ /(___(__) 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ / \ 0.0 in | 0% │ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
┌─────────────┐
┌──────────────────────────────┬───────────────────────┤ Fri 14 Aug ├───────────────────────┬──────────────────────────────┐
│ Morning │ Noon └──────┬──────┘ Evening │ Night │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │
│ _ /"".-. 73..77 °F │ _ /"".-. 77..78 °F │ _ /"".-. 78..80 °F │ _ /"".-. 75..78 °F │
│ \_( ). ↙ 10-12 mph │ \_( ). ← 13-14 mph │ \_( ). ← 12-14 mph │ \_( ). ← 12-18 mph │
│ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │ /(___(__) 6 mi │
│ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │ 0.0 in | 0% │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Location: Toronto, Ontario, Canada [43.6529206,-79.3849007]
Follow @igor_chubin for wttr.in updates
PS C:\Users\bob> get-weather -city vancouver -short
vancouver: ⛅️ 🌡️+57°F 🌬️→12mph
PS C:\Users\bob> get-weather -city vancouver -units Metric -short
vancouver: ⛅️ 🌡️+14°C 🌬️→19km/h
#parameter order does not matter
PS C:\Users\bob> get-weather -short -units Metric -city vancouver
vancouver: ⛅️ 🌡️+14°C 🌬️→19km/h
PS C:\Users\bob> get-weather -short -units Metric -city vancouver -verbose
VERBOSE: URI: https://wttr.in/vancouver?m&format=4&lang=en
VERBOSE: GET https://wttr.in/vancouver?m&format=4&lang=en with 0-byte payload
VERBOSE: received 50-byte response of content type text/plain
VERBOSE: Content encoding: utf-8
vancouver: ⛅️ 🌡️+14°C 🌬️→19km/h
reference:
No comments:
Post a Comment