Skip to content

Instantly share code, notes, and snippets.

@dkittell
Created December 14, 2015 17:55
Show Gist options
  • Save dkittell/d11d6bf7ac03d5c52355 to your computer and use it in GitHub Desktop.
Save dkittell/d11d6bf7ac03d5c52355 to your computer and use it in GitHub Desktop.
Create TinyURL within PowerShell
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment