-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCall_GitHub_from_Powershell.ps1
More file actions
37 lines (29 loc) · 982 Bytes
/
Call_GitHub_from_Powershell.ps1
File metadata and controls
37 lines (29 loc) · 982 Bytes
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
#Get the required params
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[String]$Token,
[Parameter(Mandatory=$true)]
[String]$Username,
[Parameter(Mandatory=$true)]
[String]$Repo,
[Parameter(Mandatory=$true)]
[String]$Filename
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$URI = "https://api.github.com/repos/$Username/$Repo/contents/$FileName"
$Headers = @{
accept = "application/vnd.github.v3.raw"
authorization = "Token " + $Token
}
Try
{
Write-Host "Starting powershell script $Filename from $Repo..." -ForegroundColor Yellow
$Script = Invoke-RestMethod -Uri $URI -Headers $Headers
Invoke-Expression $Script
}
catch [System.Net.WebException]
{
Write-Host "Error connecting to $Filename. Please check your file name or repo name and try again." -ForegroundColor Red
}
Write-Host "Success. Now executing $Filename from $Repo." -ForegroundColor Green