Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active December 23, 2017 06:46
Show Gist options
  • Save turboBasic/0b52f850fa51c662737d8173e5c9468e to your computer and use it in GitHub Desktop.
Save turboBasic/0b52f850fa51c662737d8173e5c9468e to your computer and use it in GitHub Desktop.
[Get-GistFiles.ps1] Gets list of files inside the GitHub gists of a user. #powershell #github
#Requires -Version 3
#Requires -Modules Posh-Gist
function Get-GistFiles {
<#
.SYNOPSIS
Gets list of files inside the GitHub gists of a user
.DESCRIPTION
Gets list of files inside the GitHub gists of a user. GitHub API is not very convenient
in retrieving file names and URIs as they are buried deeply in the API Json's in an object indexed by
file names instead of plain arrays/lists. This is especially frustrating if you don't know
file names. Get-GistFiles returns filenames in ordinary Array.
.PARAMETER User
Github account to look for gists. If absent, random 30 public gists will be fetched as per
GitHub API realization
.EXAMPLE
(Get-GistFiles -User dfinke).Files | Where Language -eq Javascript
.EXAMPLE
(Get-GistFiles -User dfinke).Files | Where Filename -like *.psm1
.NOTES
(c) 2017 @turboBasic / Andriy Melnyk
#>
[CmdletBinding(
ConfirmImpact = 'Low'
)]
Param(
[Parameter(
Position = 0,
Mandatory = $False,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[String]
$User
)
Posh-Gist\Get-Gist -User $User |
ForEach-Object {
$id = $_.id
$description = $_.description;
$url = $_.url
$files = $_.files
[Array] $properties = $files.psObject.properties
[psCustomObject] @{
id = $id
url = $url
files = @(
$properties.Name |
ForEach-Object {
@{
filename = $files.$_.filename
size = $files.$_.size
language = $files.$_.language
raw_url = $files.$_.raw_url
}
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment