Created
January 12, 2015 20:20
-
-
Save nojaf/d97d3fec6895d8c3ffb2 to your computer and use it in GitHub Desktop.
Powershell Gist example
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
# Stop script on errors | |
$ErrorActionPreference = "Stop" | |
$user = Read-Host "Enter a github user" | |
$url = [string]::Format("https://api.github.com/users/{0}/gists", $user); | |
$gistsResponse = Invoke-WebRequest $url | |
$gists = $gistsResponse.Content | ConvertFrom-Json | |
$file = New-Item "gist.html" -ItemType "file" -Force | |
$outputStream = New-Object -TypeName "System.IO.StreamWriter" -ArgumentList @($file, $true) | |
$outputStream.WriteLineAsync("<html>"); | |
$outputStream.WriteLineAsync("<head><title>My gist files</title></head>"); | |
$outputStream.WriteLine("<body>"); | |
# Loop through all gists | |
$gists | ForEach-Object { | |
# $_ is the item in the foreach | |
Write-Output $_ | |
$link = [string]::Format("<a href='{0}' target='_blank'>{1}</a><br />", $_.html_url, $_.description); | |
$outputStream.WriteLine($link); | |
} | |
$outputStream.WriteLine("</body>"); | |
$outputStream.WriteLineAsync("</html>"); | |
# Close stream | |
$outputStream.Close(); | |
$outputStream.Dispose(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment