@@ -8,23 +8,76 @@ $Global:VerbosePreference = 'SilentlyContinue'
88function Test-AzureRMTemplate () {
99 [CmdletBinding ()]
1010 param (
11- [Parameter (Mandatory = $true , HelpMessage = " Template directory or TemplateFullPath to Validate" )]
11+ [Parameter (Mandatory = $true , HelpMessage = " Template directory or TemplateFullPath to Validate" , ParameterSetName = " local " )]
1212 [ValidateScript ( { Test-Path - Path $_ })]
1313 [String ] $TemplatePath ,
14+
15+ [Parameter (Mandatory = $true , HelpMessage = " Template url to Validate" , ParameterSetName = " url" )]
16+ [String ] $TemplateUrl ,
17+
18+ [Parameter (ParameterSetName = " local" )]
19+ [Parameter (ParameterSetName = " url" )]
1420 [Parameter (HelpMessage = " Template Pattern to match.Default is *azuredeploy.json" )]
1521 [String ] $TemplatePattern = " *azuredeploy.json" ,
22+
1623 [Parameter (Mandatory = $true , HelpMessage = " Cloud Capabilities JSON File Name in the current folder or with full path" )]
24+ [Parameter (ParameterSetName = " local" )]
25+ [Parameter (ParameterSetName = " url" )]
1726 [ValidateScript ( { Test-Path - Path $_ })]
1827 [String ] $CapabilitiesPath ,
28+
1929 [Parameter (HelpMessage = " Set to process VMImages , VMExtensions & VMSizes" )]
30+ [Parameter (ParameterSetName = " local" )]
31+ [Parameter (ParameterSetName = " url" )]
2032 [Switch ] $IncludeComputeCapabilities ,
33+
2134 [Parameter (HelpMessage = " Set to process Storage Skus" )]
35+ [Parameter (ParameterSetName = " local" )]
36+ [Parameter (ParameterSetName = " url" )]
2237 [Switch ] $IncludeStorageCapabilities ,
38+
2339 [Parameter (HelpMessage = " Output Report FileName" )]
40+ [Parameter (ParameterSetName = " local" )]
41+ [Parameter (ParameterSetName = " url" )]
2442 [String ] $Report = " TemplateValidationReport.html"
2543 )
44+
2645 $capabilities = ConvertFrom-Json (Get-Content - Path $CapabilitiesPath - Raw) - ErrorAction Stop
27- $TemplateDirectory = Get-ChildItem - Path $TemplatePath - Recurse - Include $TemplatePattern
46+
47+ if ($PSCmdlet.ParameterSetName -eq " url" )
48+ {
49+ $pathTokens = $TemplateUrl.Split (" /" )
50+ $filename = $pathTokens [-1 ]
51+ $fileDir = $pathTokens [-2 ]
52+ $rootPath = $env: TEMP
53+
54+ $localDirPath = Join-Path - Path $rootPath - ChildPath $fileDir
55+
56+ if (Test-Path ($localDirPath ))
57+ {
58+ Remove-Item - Path $localDirPath - Recurse - Force - ErrorAction Stop
59+ }
60+
61+ New-Item - Path $localDirPath - ItemType Directory - Force | Out-Null
62+
63+ $sourcePath = Join-Path - Path $localDirPath - ChildPath $filename
64+ Invoke-WebRequest - Uri $TemplateUrl - OutFile $sourcePath - Verbose - ErrorAction Stop
65+
66+ if ([IO.Path ]::GetExtension($filename ) -eq " .zip" )
67+ {
68+ $expandedPath = Join-Path - Path $localDirPath - ChildPath ([IO.Path ]::GetFileNameWithoutExtension($filename ))
69+ Expand-archive $sourcePath - DestinationPath $expandedPath - ErrorAction Stop
70+ $sourcePath = $expandedPath
71+ }
72+
73+ }
74+ else
75+ {
76+ $sourcePath = $TemplatePath
77+ }
78+
79+
80+ $TemplateDirectory = Get-ChildItem - Path $sourcePath - Recurse - Include $TemplatePattern
2881 $reportOutPut = @ ()
2982 $totalCount = 0
3083 $warningCount = 0
0 commit comments