Created
November 6, 2017 18:10
-
-
Save SteGriff/2d5e53b8c52acb65cc0d37768d4483de to your computer and use it in GitHub Desktop.
PowerShell script to recurse thru azure-quickstart-templates, pulling out every azuredeploy.json file and listing the Resource.Types they use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script to recurse thru github.com/azure/azure-quickstart-templates, | |
# pulling out every azuredeploy.json file and listing the Resource.Types they use | |
# Initialise an empty list of $types and an optional $limit for how many files to process | |
$types = @() | |
$limit = 100 | |
# Set up your cloned repo directory here | |
$directory = 'C:\Projects\Ste\azure-quickstart-templates' | |
cd $directory | |
# Get all files recursively which are 'azuredeploy.json' | |
# Optionally limit the number of files taken (comment it in/out) | |
Get-ChildItem -Recurse -Filter 'azuredeploy.json' | #select -first $limit | | |
ForEach { | |
# Get the JSON text content of this one file | |
$content = Get-Content $_.FullName | Out-String | |
# Get this one file as a PowerShell object | |
$obj = ConvertFrom-Json $content | |
# Get all the 'Resource.Type' paths from this file in a list | |
$lines = $obj | Select @{n='Type';e={$_.Resources.Type}} | |
# Now, each .Type can be an array. So we're going to Each over those | |
# and add each type and array-contained type to the master list | |
$lines.Type | ForEach { | |
$types += $_ | |
} | |
} | |
# Output the distinct types, sorted alphabetically. | |
$types | Sort -Unique |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment