Loading...

Retrieve Cloud Service Extended Support detail via PowerShell

Retrieve Cloud Service Extended Support detail via PowerShell

This blog is mainly about how to retrieve the CSES configuration via PowerShell and REST API. It will cover the following sections: 

  • PowerShell command to get the CSES configuration
  • PowerShell to send out REST API request to get the CSES configuration 
  • Sample to retrieve OS Family, OS Version and any other data 

 

Prerequisites

No matter PowerShell command or Rest API request will be used to get the information, the PowerShell Azure Az module is necessary. For the installation details, please refer to this document.

 

PowerShell command to get the CSES configuration 

To use Get-AzCloudService (Az.CloudService) | Microsoft Learn to get the CSES configuration data, we can follow these steps: 

  1. Use command Connect-AzAccount to login
  2. Use command Get-AzCloudService to get the full picture of your CSES resource and save it into a PowerShell variable such as $cses in the following example 
  3. Convert the configuration of the CSES into XML format.  

The used commands will be: 

 

Connect-AzAccount $cses = Get-AzCloudService -ResourceGroupName “xxx” -CloudServiceName “xxx” [xml]$xml = $cses.Configuration

 

 

Example of PowerShell commandExample of PowerShell command

 

PowerShell to send out REST API call to get the CSES configuration 

To use Cloud Services - Get - REST API (Azure Compute) | Microsoft Learn to get the CSES configuration data by sending out REST API call in PowerShell, we can follow these steps: 

  1. Use command Connect-AzAccount to login 
  2. Use command Invoke-AzRestMethod to send out the REST API call. The path in the command will be the same for every user except the value such as your own subscription ID, resource group name and CSES resource name. Once we get the response, we can use some additional PowerShell function like convertfrom-json to proceed the data and then save it into a PowerShell variable such as $csesapi in the example 
  3. Convert the configuration of the CSES into XML format 

 

The used commands will be: 

 

Connect-AzAccount $csesapi = (Invoke-AzRestMethod -Path "/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/cloudServices/{CSES-resource-name}?api-version=2021-03-01").Content | convertfrom-json [xml]$xml = $csesapi.properties.configuration

 

 

Example of REST API requestExample of REST API request

 

Sample about how to get OS Family, OS Version and any other data 

No matter PowerShell command or REST API is used, with above instruction, the $xml from both ways will be the same. 

 

Basically, this is how my example CSES configuration data looks like: 

Example of configuration data of CSESExample of configuration data of CSES

 

The $xml is the whole configuration file in XML format. In order to get the data, such as osFamily, osVersion or VirtualNetworkSite, following the construction of this XML file to add related name to identify the data of which level is needed will be enough. 

 

For example, for osVersion/osFamily, the path to it will be ServiceConfiguration -> osVersion/osFamily. So the expression to use in PowerShell to get the data will be: 

 

$xml.ServiceConfiguration.osVersion / $xml.ServiceConfiguration.osFamily

 

Example expression for osFamily/osVersionExample expression for osFamily/osVersion

 

And for the VirtualNetworkSite, the path to it will be ServiceConfiguration -> NetworkConfiguration -> VirtualNetworkSite -> name. So the expression to use in PowerShell to get the data will be: 

 

$xml.ServiceConfiguration.NetworkConfiguration.VirtualNetworkSite.name

 

Example expression of Virtual Network nameExample expression of Virtual Network name

 

Note: It’s possible that we have more than one role in our configuration, the expression to locate a role which is not the first role will be $xml.ServiceConfiguration.Role[1]. The number “1” here means the second role in the configuration data because this counter starts from 0. If there are two roles in same configuration data, the expression $xml.ServiceConfiguration.Role[1].Instances.count will be able to return how many instances there are for the second role. 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Azure Storage - TLS 1.0 and 1.1 retirement

Overview TLS 1.0 and 1.1 retirement on Azure Storage was previously announced for Nov 1st, 2024, and it was postponed recently to 1 year later...

1 year ago

Efficient Management of Append and Page Blobs Using Azure Storage Actions

  Overview In Azure Storage, Blob Lifecycle Management (BLM) allows you to automate the management of your data based on rules defined by...

1 year ago

[Azure AI Search] Internal Server Error when creating CMK encrypted objects

Scenario Customers follow the Microsoft doc to create CMK encrypted objects (data source, index etc.), but get the 500 Internal Serv...

1 year ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Restoring Soft-Deleted Blobs with multithreading in Azure Storage Using C#

Blob soft delete is an essential feature that safeguards your data against accidental deletions or overwrites. By retaining deleted data for a...

1 year ago

Performing simple Azure Table Storage REST API operations using curl command.

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entit...

1 year ago

Bulk delete all the old jobs from the batch account

Deleting a Job also deletes all Tasks that are part of that Job, and all Job statistics. This also overrides the retention period for Task dat...

1 year ago

Utilizing Azure Storage and Runbooks for scheduled automated backups of Azure SQL Databases

In this article, we are going to provide detailed steps to create a scheduled Azure SQL Database backup to storage account using automation. T...

2 years ago

[Azure Service Bus] JMS messages getting dead-lettered

The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer connects to th...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.