Comment on Making Short Links Long with PowerShell and WPF

I like reviewing how other folks approch things, and the in cool and all but, why the use of a form for this, just to be thrown back to the console, when you can just use a function with a param and stay in the console (still using copy and paste)? Using this function… Function Resolve-TinyUrl { [CmdletBinding()] [Alias(‚rturl’)] Param( [Parameter(Mandatory=$true, HelpMessage=”Enter a valid Url”)] [ValidatePattern(‚(?# Enter a valid Url)^(ftp:|http:|https:|ftp:)(//.*)’)] [string]$ShortUrl ) „The URL entered – $ShortUrl is valid” Start-Sleep -Seconds 1 $longURL = (Invoke-WebRequest -UseBasicParsing –Uri $ShortUrl).baseresponse.ResponseUri.AbsoluteURI „The ShortUrl ‚$shortUrl’ Resolves to -> ‚$longUrl'” } … or for a bit more info or control aspects, this one Function Expand-Url { [CmdletBinding()] [Alias(‚eurl’)] Param( [Parameter(Mandatory=$true, HelpMessage=”Enter a valid Url”)] [ValidatePattern(‚(?# Enter a valid Url)^(ftp:|http:|https:|ftp:)(//.*)’)] [string]$URLRaw ) „The URL entered – $URLRaw is valid” Start-Sleep -Seconds 1 (Invoke-WebRequest -Uri $URLRaw -MaximumRedirection 0 -ErrorAction Ignore).Headers.Location $result = [System.uri](Invoke-WebRequest -Uri $URLRaw -MaximumRedirection 0 -ErrorAction Ignore).Headers.Location „Port: $($result.port)” „Page Authority: $($result.Authority)” „Served using: $($result.Scheme)” }

GD Star Rating
loading...