-
-
Save tadcrazio/392a4fb45d11fc1ec7bbbfe5c302ba55 to your computer and use it in GitHub Desktop.
URL Shortener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function URL | |
{ | |
[PoshBot.BotCommand( | |
Command = $false, | |
CommandName = 'URL', | |
TriggerType = 'Regex', | |
Regex = '^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)|[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}[^ ]+' | |
)] | |
[cmdletbinding()] | |
param( | |
[parameter(ValueFromRemainingArguments)] | |
[object[]]$Arguments | |
) | |
try { | |
$key = '{APIKEYHERE}' | |
$toshorten = (new-object PSObject | | |
Add-Member -Passthru NoteProperty longUrl $url )|convertto-json | |
$goo = Invoke-RestMethod -Uri https://www.googleapis.com/urlshortener/v1/url?key=$key -Body $toshorten -ContentType application/json -Method Post | |
Write-Output "Nice link, I made it better $($goo.id)" | |
} | |
catch [System.Net.Webexception] | |
{ | |
$Error | Out-File C:\Scripts\logs\t.log -Append | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment