public/Remove-GitHubGist.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<#
.Synopsis The function remove GitHub Gists .DESCRIPTION All documentation find you on https://developer.github.com/v3/gists/#delete-a-gist .EXAMPLE Remove-GithubGist -UserName 'mnadobnik' -Token 'bc972823d9c79084ebfaefdc7ee98cbc1d259d1c' -Id '7cfe221a77c7110fb3a33b3c297a69a9' Delete a gist .EXAMPLE Get-GithubGist | Where-Object files -like *gist-test* | Remove-GithubGist .NOTES Author: Mateusz Nadobnik Link: akademiapowershell.pl Date: 02-12-2019 Version: version eywords: keywords Notes: Changelog: #> function Remove-GithubGist { [Alias('Remove-Gist')] [cmdletbinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [string]$UserName, [Parameter(Mandatory)] [string]$Token, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [Alias('GistId')] [string]$Id ) begin { $Token = ('{0}:{1}' -f $UserName, $Token) $BaseAuth = [System.Convert]::ToBase64String([char[]]$Token) $Header = @{ Authorization = "Basic $BaseAuth" } } process { if ($PSCmdlet.ShouldProcess($Id)) { try { $Uri = "https://api.github.com/gists/$Id" Write-Verbose ($Header.Authorization) $Result = Invoke-RestMethod -Uri $Uri -Method Delete -Headers $Header Write-Output $Result } catch { Write-Warning $_.Error } } } } |