Saturday, June 21, 2008

Generating TinyURLs from PowerShell

 

TinyURL is a web service that provides short aliases for long URLs. Here's a function to generate URL aliases using TinyURL's API. The returned URL is short and never expires.

 
function New-TinyUrl($url){
    (new-object net.webclient).downloadString("http://tinyurl.com/api-create.php?url=$url") 
}
 
PS > $vug = New-TinyUrl -url http://marcoshaw.blogspot.com/2008/06/windows-powershell-virtual-user-group.html
PS > $vug
PS > http://tinyurl.com/4k9ons

 

Test it in your default browser:

PS > (new-object -com shell.application).open($vug) 

 

-Shay

2 comments:

Jeffery Hicks said...

My Out-Twitter function (http://blog.sapien.com/index.php/2008/06/23/out-twitter/) uses something similar but with Snurl

Function Get-Snurl {
Param([string]$link="http://www.google.com")
$webclient=New-Object Net.WebClient
$url="http://snipurl.com/site/snip?r=simple&link=$link"
$response=$webclient.DownloadString("$url")
write $response
}

Raobabu said...

Thanks for thiis blog post