Here is the completed script.
<# .SYNOPSIS Will create a new vExpert.me URL .DESCRIPTION Using the Invoke-Rest Cmdlet to invoke a creation of a new vExpert.me URL .PARAMETER URL URL that should be shortened. .PARAMETER Custom The custom URL that should be used. .EXAMPLE PS C:\> New-vExpertURL -URL 'http://www.google.com' This example shows how to call the New-vExpertURL function with with the URL parameter and generate a random URL. .EXAMPLE PS C:\> New-vExpertURL -URL 'http://www.google.com' -Custom this_is_my_link This will create a custome URL of http://vexpert.me/this_is_my_link pointing to http://www.google.com .INPUTS System.String .OUTPUTS System.String .NOTES For more information about advanced functions, call Get-Help with any of the topics in the links listed below. #> function New-vExpertURL { [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$true)] [System.String]$URL, [Parameter(Position=1)] [System.String]$Custom ) begin { if (!$($Custom) ) { $baseurl_2 = "&action=shorturl&format=json&url=" } else { $baseurl_2 = "&action=shorturl&keyword=" + $Custom + "&format=json&url=" } $baseurl_1 = "http://vexpert.me/yourls-api.php?signature=" $secret = "xxxxxxxxx" } process { $invokeurl = $baseurl_1 + $secret + $baseurl_2 + $URL $vExpertme = Invoke-RestMethod -Uri $invokeurl $vExpertme.shorturl | clip Write-Host "The shortenend URL is now in your clipboard" -ForegroundColor Green } end { } }
So I added 4 things
- This is now a function – and it accepts parameters.
- One of the parameters is CustomURL which will allow you to enter your custom text if you please.
- The output will provide the URL and a success message.
- The URL will now be in your clipboard so you can use it.