2

I am trying to call the contents of a PS1, as raw, in Powershell out of Github. In GitLab this is doable by calling the following:

https://gitlab.com/USER/PRIVATEREPOS/raw/master/FileShares/SCRIPT.ps1?private_token=TOKENHERE

I am hoping there is a similar way to do this with GitHub - I've tried numerous things but none have worked. Any help would be appreciated.

Trinitrotoluene
  • 1,388
  • 5
  • 20
  • 39

2 Answers2

0

You could try a similar URL, but using:

That should serve the raw content of that ps1 script.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

This is done by getting to the same resources via a different url - raw.githubusercontent.com (hosted by github not a third-party). If it is a private repository, you'll need:

  • a personal access token referenced in the header of the request
  • the project path on github
  • the name of the script you're trying to get

To jump straight to the PowerShell code needed, it would be-

$baseurl = "https://raw.githubusercontent.com/yourproject/subdir/master"
$tokenheaders = @{"Authorization"="token tokenyougeneratedforprivateprojectaccess";"Accept"= "application/vnd.github.v3.raw"}
$scripturl="$baseurl/yourscript.ps1"
Invoke-WebRequest -Uri $scripturl -Headers $tokenheaders -UseBasicParsing |Select-Object -ExpandProperty Content  

This will get you the raw code, not a file, and this is using the deprecated v3 of the api, not v4 (but is still working for me as of this writing and should for at least a few more years).

danno
  • 277
  • 3
  • 7