Skip to content

Instantly share code, notes, and snippets.

@rodmhgl
Last active June 30, 2017 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodmhgl/300484237371686c94ad76a4e82cb911 to your computer and use it in GitHub Desktop.
Save rodmhgl/300484237371686c94ad76a4e82cb911 to your computer and use it in GitHub Desktop.
Grabs a random tip from the Git-Tips Github repository
Function Get-GitTip {
<#
.SYNOPSIS
Grabs a random tip from the Git-Tips Github repository
.DESCRIPTION
Grabs a random tip from the Git-Tips Github repository
Designed to be used as part of my $profile to receive a daily tip
.PARAMETER URI
URI of the Tips.JSON file - defaults to the master branch of the git-tips repository
.EXAMPLE
Get-GitTip
.NOTES
Relies on the Git-tips repository on Github - https://github.com/git-tips/tips
#>
[cmdletbinding()]
param(
[Parameter(Position = 0, HelpMessage = "The URL to git-tips JSON file")]
[ValidateScript( {
$TipList = Invoke-WebRequest -URI $_ -Verbose -ErrorAction Stop
if ($TipList) { $true } else { Throw "Cannot Validate URI Parameter"}
})]
$URI = 'https://raw.githubusercontent.com/git-tips/tips/master/tips.json'
)
try {
$TipList | ConvertFrom-Json | Get-Random
} catch { Write-Error -Message "Unable to convert JSON - $($_)"; break}
}
Get-GitTip | Format-List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment