Use Powershell to shorten URI with bitly REST API

Hallo zusammen,

Ich habe mich ein wenig mit der REST Schnittstelle von Webapplikationen befasst.

Hier ein paar wichtige Grundlagen 

Ich habe mir mal die REST Schnittstelle von Bitly angeschaut http://dev.bitly.com/get_started.html

Danach habe ich mir das Powershell Command "Invoke-RestMethod" angeschaut

Invoke-RestMethod
https://technet.microsoft.com/en-us/library/hh849971.aspx

Nachdem ich mir einen www.bitly.com  Account angelegt hatte und ein wenig rumprobiert habe, ist folgender Powershell Code rausgekommen.


## HTTP Basic Authentication Flow
##http://dev.bitly.com/authentication.html
$user = "username"
$pass= "SecredPassword"
$uri = "https://api-ssl.bitly.com/oauth/access_token"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pass)))
$Accesstoken = Invoke-RestMethod -Method Post -uri $uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host "Access_Token: $Accesstoken" -ForegroundColor Green

##Shorten
##http://dev.bitly.com/links.html#v3_shorten
$longurl="http://www.icewolf.ch"
$uri = "https://api-ssl.bitly.com/v3/shorten?access_token=$Accesstoken&longUrl=$longurl"
$Result = Invoke-RestMethod -Method GET -uri $uri
$Result.Data
Write-Host "ShortURL: " $Result.Data.url -ForegroundColor Green

Grüsse
Andres Bohren