Public/Functions/split/Get-GithubRawUrl.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 |
function Get-GithubRawUrl { [CmdletBinding()] param ( [Parameter(Mandatory)] [System.Uri] # Github Url to retrieve $Uri ) #Write-Warning 'GithubRaw functions are currently under development' #Write-Warning 'Functionality is subject to change until this warning is removed' if ($Uri -match 'gist.github.com') { try { $GetUri = (Invoke-WebRequest -UseBasicParsing -Method Get -Uri $Uri).Links | Where-Object {($_.outerHTML -match 'RAW') -and ($_.class -match 'btn-sm btn')} | Select-Object -ExpandProperty href $GetUri = $GetUri | ForEach-Object {"https://gist.githubusercontent.com$_" -replace '\/raw\/[\w-]{40}','/raw'} $GetUri } catch { Write-Warning $_ } } elseif ($Uri -match 'github.com') { try { $GetUri = (Invoke-WebRequest -UseBasicParsing -Method Get -Uri $Uri).Links | Where-Object {($_.outerHTML -match 'RAW') -and ($_.class -match 'btn-sm btn')} | Select-Object -ExpandProperty href $GetUri = $GetUri -replace '/raw/','/' $GetUri = $GetUri | ForEach-Object {"https://raw.githubusercontent.com$_"} $GetUri } catch { Write-Warning $_ } } elseif (([System.Uri]$Uri).AbsoluteUri) { ([System.Uri]$Uri).AbsoluteUri } else { [System.String]$Uri } } |