-
Notifications
You must be signed in to change notification settings - Fork 22
/
Decompile-GithubArmTemplate.ps1
40 lines (31 loc) · 1.16 KB
/
Decompile-GithubArmTemplate.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
function Decompile-GithubArmTemplate {
[CmdletBinding()]
param (
[Parameter()]
[string]
$GithubPath,
[Parameter()]
[string]
$Path,
[Parameter()]
[string]
$FileName
)
if($GithubPath.StartsWith('https://raw.githubusercontent.com')){
Write-Verbose "Well it looks like raw content URL"
} elseif ($GithubPath.StartsWith('https://github.com')) {
Write-Verbose "Well it looks like a base Github URL"
$GithubPath = $GithubPath -replace 'github', 'raw.githubusercontent' -replace '/blob',''
$Name = $GithubPath.Split('/')[-2]
}else{
Write-Warning "Use the right path and start with https://"
Return
}
$DownloadFile = "$env:TEMP\{0}.{1}" -f $Name, 'json'
($Path) ? ($outputPath = $Path) : ($outputPath = $Pwd.Path)
($FileName) ? ($FileName) : ($FileName = "$Name.{0}" -f 'bicep')
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($GithubPath, $DownloadFile)
bicep decompile $DownloadFile --outfile "$outputPath\$FileName"
Write-Output "Decompiled $GithubPath to $outputPath\$FileName"
}