Skip to content

Instantly share code, notes, and snippets.

@rheid
Last active February 12, 2016 13:25
Show Gist options
  • Save rheid/02e7954f9742afb002db to your computer and use it in GitHub Desktop.
Save rheid/02e7954f9742afb002db to your computer and use it in GitHub Desktop.
Get-AzureResourceGroupGalleryTemplate from new Azure REST Interface
# Retrieve all available items
$allGalleryItems = Invoke-WebRequest -Uri "https://gallery.azure.com/Microsoft.Gallery/GalleryItems?api-version=2015-04-01&includePreview=true" | ConvertFrom-Json
# Get all items published by Microsoft
$allGalleryItems | Where-Object { $_.PublisherDisplayName -eq "Microsoft" }
# Get all gallery items with "SQL" in the description
$allGalleryItems | Where-Object { $_.Description -match "SQL" }
# Save default template for all items under directory "C:\Templates"
$allGalleryItems | Foreach-Object {
$path = Join-Path -Path "C:\templates" -ChildPath $_.Identity
New-Item -type Directory -Path $path
$_.Artifacts | Where-Object { $_.type -eq "template" } | ForEach-Object {
$templatePath = Join-Path -Path $path -ChildPath ( $_.Name + ".json" )
(Invoke-WebRequest -Uri $_.Uri).Content | Out-File -FilePath $templatePath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment