Posts

Showing posts from December, 2023

Get a screenshot of an Azure virtual machine programmatically using PowerShell and the Azure REST API

Image
The Boot Diagnostics menu in an Azure virtual machine displays a screenshot of the virtual machine. This screenshot is availabe in the REST API described here. https://learn.microsoft.com/rest/api/compute/virtual-machines/retrieve-boot-diagnostics-data For this to work you must use a POST method and have the "retrieveBootDiagnosticsData/action" permission. The REST API call returns an object with the URL to the image at an Azure storage URL which can then be downloaded with a web client. # Gets the screenshot for the specified virtual machine. function Get-AzureVirtualMachineScreenshot {      [ CmdletBinding () ]      param (           [ Parameter () ]           [ Guid ] $SubscriptionIdentifier ,           [ Parameter () ]           [ String ] $ResourceGroupName ,           [ Parameter () ]           [ String ] $Name      )      process      {           $response = Invoke-AzRestMethod -Path "/subscriptions/ $SubscriptionIdentifier /resourceGroups/ $ResourceGroupN

How to programatically identify the latest stable REST API version of Azure management REST

Image
If you are making direct calls to the Azure REST API you notice that you need to provide the API version for that specific REST endpoint. Sometimes the version provided in the Microsoft documentation is wrong. If you provide an invalid API version you receive an error message that contains the available API versions. However, should you wish to programatically determine the current latest API version you can use the providers API. https://learn.microsoft.com/rest/api/resources/providers For example if you would like to know the latest Web Apps API version you can call the providers API and provide the namespace in which the Web Apps API resides (the provider API version is currently 2021-04-01). https://management.azure.com/providers/Microsoft.Web?api-version=2021-04-01 As you can see from the results here shown in Postman  there is a resource type of "Sites" (again Microsoft are a bit inconsistent in their naming between the API and the documentation - web apps are infact &q

Azure Web App "Application Settings" and "Connection Strings" section missing from "Configuration" Section in the Azure Portal

Image
You may find that you can't locate the "Application Settings" and "Connection Strings" sections for an Azure Web App. This is because Microsoft's documentation is often wrong. https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal These settings are no longer under "Settings > Configuration", but are now under "Settings > Environment Variables".