PowerShell – Get-TinyURL API Call

|
clear
Function Get-TinyURL { 
    #PowerShell - Get-TinyURL API Call
    param (
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)] 
        [String]
        $sHTTPLink
    )

    if ($sHTTPLink.StartsWith("http://") -eq $true -or $sHTTPLink.StartsWith("https://") -eq $true)
        {
            if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient }
            $webClient.DownloadString("http://tinyurl.com/api-create.php?url="  + [System.Web.HttpUtility]::UrlEncode($sHTTPLink))
        }
    else
        {
            Write-Output "Bad Link, please include http:// or https://"
        }
}

Get-TinyURL "http://google.com"

GitHub: https://gist.github.com/dkittell/d11d6bf7ac03d5c52355

Originally Posted on December 14, 2015
Last Updated on February 12, 2016
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.