Created
December 6, 2017 02:16
-
-
Save markdmac/9279170fd5c27254e5762440cc600c83 to your computer and use it in GitHub Desktop.
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
#========================================================================== | |
# | |
# NAME: MakeTinyURL.ps1 | |
# | |
# AUTHOR: Mark D. MacLachlan, US Foods | |
# DATE : 02/17/2017 17:17:41 | |
# | |
# This code is copyright (c) 2017 US Foods. | |
# | |
# All rights reserved. | |
# | |
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF | |
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A | |
# PARTICULAR PURPOSE. | |
# | |
# IN NO EVENT SHALL US FOODS AND/OR ITS RESPECTIVE SUPPLIERS BE | |
# LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY | |
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
# OF THIS CODE OR INFORMATION. | |
# | |
# COMMENT: | |
# | |
#========================================================================== | |
function get-tinyurl{ | |
<# | |
.Synopsis | |
Converts a URL into a Tiny URL | |
.Description | |
Converts URL to Tiny URL. | |
Parameter URL | |
enter entire URL to be converted to a tiny url. i.e. https://weeklypowershellscript.wordpress.com/ | |
.Example | |
.\get-tinyurl -URL https://weeklypowershellscript.wordpress.com/ | |
In this example https://weeklypowershellscript.wordpress.com/ gets converted to a tiny url. | |
#> | |
[cmdletBinding()] | |
Param( | |
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory=$TRUE)] | |
[String]$URL | |
) | |
$url = "http://tinyurl.com/api-create.php?url=$URL" | |
$webclient = New-Object -TypeName System.Net.WebClient | |
$TinyURL=$webclient.DownloadString($url) | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
$objForm = New-Object System.Windows.Forms.Form | |
$objForm.Text = "TinyURL" | |
$objForm.Size = New-Object System.Drawing.Size(300,200) | |
$objForm.StartPosition = "CenterScreen" | |
$objForm.KeyPreview = $True | |
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") | |
{$Global:x = $objTextBox.Text | |
$objForm.Close()}}) | |
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") | |
{$objForm.Close()}}) | |
$OKButton = New-Object System.Windows.Forms.Button | |
$OKButton.Location = New-Object System.Drawing.Size(75,120) | |
$OKButton.Size = New-Object System.Drawing.Size(75,23) | |
$OKButton.Text = "OK" | |
$OKButton.Add_Click({$Global:x = $objTextBox.Text | |
$objForm.Close()}) | |
$objForm.Controls.Add($OKButton) | |
$CancelButton = New-Object System.Windows.Forms.Button | |
$CancelButton.Location = New-Object System.Drawing.Size(150,120) | |
$CancelButton.Size = New-Object System.Drawing.Size(75,23) | |
$CancelButton.Text = "Cancel" | |
$CancelButton.Add_Click({$objForm.Close()}) | |
$objForm.Controls.Add($CancelButton) | |
$objLabel = New-Object System.Windows.Forms.Label | |
$objLabel.Location = New-Object System.Drawing.Size(10,20) | |
$objLabel.Size = New-Object System.Drawing.Size(280,20) | |
$objLabel.Text = "TinyURL is:" | |
$objForm.Controls.Add($objLabel) | |
$objTextBox = New-Object System.Windows.Forms.TextBox | |
$objTextBox.Location = New-Object System.Drawing.Size(10,40) | |
$objTextBox.Size = New-Object System.Drawing.Size(260,20) | |
$objForm.Controls.Add($objTextBox) | |
$objTextBox.Text = $TinyURL | |
$objForm.Topmost = $True | |
$objForm.Add_Shown({$objForm.Activate()}) | |
[void] $objForm.ShowDialog() | |
} | |
$longURL = "http://1pxprrfxap03.usf.ad.usfood.local/webutil/forms/OpenServer.aspx?Server=1pxprrfxap01" | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
$objForm = New-Object System.Windows.Forms.Form | |
$objForm.Text = "Long URL Entry Form" | |
$objForm.Size = New-Object System.Drawing.Size(650,200) | |
$objForm.StartPosition = "CenterScreen" | |
$objForm.KeyPreview = $True | |
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") | |
{$Global:x = $objTextBox.Text | |
$objForm.Close()}}) | |
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") | |
{$objForm.Close()}}) | |
$OKButton = New-Object System.Windows.Forms.Button | |
$OKButton.Location = New-Object System.Drawing.Size(75,120) | |
$OKButton.Size = New-Object System.Drawing.Size(75,23) | |
$OKButton.Text = "OK" | |
$OKButton.Add_Click({$Global:x = $objTextBox.Text | |
$objForm.Close()}) | |
$objForm.Controls.Add($OKButton) | |
$CancelButton = New-Object System.Windows.Forms.Button | |
$CancelButton.Location = New-Object System.Drawing.Size(150,120) | |
$CancelButton.Size = New-Object System.Drawing.Size(75,23) | |
$CancelButton.Text = "Cancel" | |
$CancelButton.Add_Click({$objForm.Close()}) | |
$objForm.Controls.Add($CancelButton) | |
$objLabel = New-Object System.Windows.Forms.Label | |
$objLabel.Location = New-Object System.Drawing.Size(10,20) | |
$objLabel.Size = New-Object System.Drawing.Size(280,20) | |
$objLabel.Text = "Please enter long URL:" | |
$objForm.Controls.Add($objLabel) | |
$objTextBox = New-Object System.Windows.Forms.TextBox | |
$objTextBox.Location = New-Object System.Drawing.Size(10,40) | |
$objTextBox.Size = New-Object System.Drawing.Size(600,20) | |
$objForm.Controls.Add($objTextBox) | |
$objForm.Topmost = $True | |
$objForm.Add_Shown({$objForm.Activate()}) | |
[void] $objForm.ShowDialog() | |
#Global variable x holds our data. | |
$Global:x | |
get-tinyurl $Global:x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment