2015年12月3日木曜日

◆空港の場所と天気を調べる(New-WebServiceProxy)

 

New-WebServiceProxyコマンドレットを使ったことがなかったのでメモしておく。

Getting Airports and Weather Info near You - Power Tips - PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources

WEBサービスを簡単に呼び出せるのね。

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021

$uri = 'http://www.webservicex.net/globalweather.asmx?WSDL'
function Get-Airport
{
 
param($Country, $City='*'
)
 
$webservice = New-WebServiceProxy -Uri $uri
 
 
$data = [xml]$webservice.GetCitiesByCountry($Country
)
 
$data.NewDataSet.Table |
  Where-Object { $_.City -like "*$City*"
 }
}

function Get-Weather
{
 
param($City, $Country='Germany'
)
 
$webservice = New-WebServiceProxy -Uri $uri
  $data = [xml]$webservice.GetWeather($City, $Country
)
 
$data.
CurrentWeather
}


[System.Net.ServicePointManager]::Expect100Continue = $false
#Get-Airport -Country Japan | sort city
#Get-Weather -Country Bahamas -City 'Freeport, Grand Bahama'

Get-Weather -Country Japan -City 'Hanamaki airport'

image