Monday, February 29, 2016

Get-AzureResourceGroupGalleryTemplate is missing (and a fix)

Last September, I wrote about what I call ‘The Great Azure Cmdlet Renaming’. Well, I’m now in the process of actually using the resultant cmdlets and I am having some minor frustrations.

I am following an Azure Resource Manager training course, provided by Microsoft MVA. I suppose it’s bad enough that EVERY demo shows stuff that no longer exists – all the demos are ‘wrong’. The new portal looks vastly different from the course, although with a bit of effort I can pretty much re-produce what the demos are showing. It’s tedious, but possible in most cases. And just for the record: the latest incarnations of the portal are very good - much better than in the MVA video.

But it’s not just the portal that is so different in the video, the cmdlets have changed too – with lots of renaming, etc. One cmdlet that is now totally gone is Get-AzureResourceGroupGalleryTemplate. This cmdlet returned a list of templates in Azure’s gallery along with details of the specific template.

So, while you can’t actually use this cmdlet (it no longer exists), you can re-create it like this:
Function Get-AzureResourceGroupGalleryTemplate {[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,
           Position=0,
           ParameterSetName='Default')]
[Alias("ip")]
$IncludePreview = $false
)
#
$StartTime = Get-Date
Write-Verbose "Started at $StartTime"
#     Create URL
$GalleryUri = "
https://gallery.azure.com/Microsoft.Gallery/GalleryItems?api-version=2015-04-01"
if ($IncludePreview)
   { $GalleryUri += "&includePreview=true"}
Else
   { $GalleryUri += "&includePreview=false"}
#    Retrieve all available templates
Try   {
         $AllGalleryTemplates = Invoke-WebRequest -Uri $GalleryUri | ConvertFrom-Json
      }
Catch {
         "Error invoking Call to Azure Gallery"
      }
#     Write verbose return information
$EndTime = Get-Date
Write-Verbose "Finished at $EndTime"
Write-Verbose "$(($EndTime-$StartTime).totalseconds) seconds elapsed"
Write-Verbose "Templates returned: $($AllGalleryTemplates.count)"
#     And return it
Return $AllGalleryTemplates
}

Set-Alias Get-RGTemplate Get-AzureResourceGroupGalleryTemplate
Set-Alias GRGT Get-AzureResourceGroupGalleryTemplate
It’s easy enough to re-create the template – I’m not sure why it was removed in the first place. If, like me, you think that the cmdlet should be re-instated, then feel free to follow up at: https://github.com/Azure/azure-powershell/issues/1885

No comments: