I’ve been using PowerShell quite a bit of late, bit of a small learning curve but when you get into it it really is amazingly powerful (hence the name I suppose!). The ability to pipe objects, and not just text, makes it excellent ‘glue’ for which to bind things together (e.g. data in SQL Server, Excel, Email, your own .NET components/services, etc).
In the last while, I’ve been using PowerShell 2.0 in Windows 7, and with it the excellent ‘New-WebServiceProxy’ cmdlet. This allows you to use Web Service API’s directly from the shell, which I’m finding incredibly useful. (You could do this in Powershel 1.0 but it was a bit more involved)
Here’s a short example of using a relatively non-trivial Web Service, the BetFair API:
#short script to log on to Betfair and grab some upcoming events
$bfExchange = New-WebServiceProxy -uri https://api.betfair.com/exchange/v5/BFExchangeService.wsdl -Namespace BFE
$bfGlobal = New-WebServiceProxy -uri https://api.betfair.com/global/v3/BFGlobalService.wsdl -Namespace BFG
$loginReq = new-object BFG.LoginReq
$loginReq.username = <your betfair username>
$loginReq.password = <your betfair password>
$loginReq.productId = 82
$loginReq.vendorSoftwareId = 0
$loginResp = $bfGlobal.login($loginReq)
# Get some Betfair Events, happening in the next 3 hours
$marketsReq = New-Object BFE.GetAllMarketsReq
$marketsReq.header = New-Object BFE.APIRequestHeader
$marketsReq.header.sessionToken = $loginResp.header.sessionToken
$marketsReq.fromDate = Get-Date
$marketsReq.toDate = (Get-Date).AddHours(3)
# Invoke the call
$marketResp = $bfExchange.getAllMarkets($marketsReq)
# The format of the Markets, etc, is all documented here:
# http://bdphelp.betfair.com/API6/6.0/RefGuide/wwhelp/wwhimpl/js/html/wwhelp.htm
foreach($market in $marketResp.marketData.Split(':')) {
$data = $market.Split('~')
Write-Host "Market: " $data[1] "Path: " $data[5]
}
Although trivial, its a good example of ‘feeling your way around’ an external Web Service without having to write any real code (i.e. fire up VSTS).
If your thinking of trying out powershell, give PowerGui a look, and I also find Console to be way better than the default Windows cmd. I’ve also plenty of Powershell links bookmarked on delicious.