Jump to content

Retrieve Cloud Service Extended Support detail via PowerShell


Recommended Posts

Posted

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 = $cses.Configuration 

 

 

 

 

 

largevv2px999.png.e064df5bb980c1db83eba8bd6d6de53f.pngExample of PowerShell command

 

 

 

[size=5][b][b]PowerShell to send out REST API call to get the CSES configuration [/b][/b][/size]

 

 

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 [b]your own subscription ID[/b], [b]resource group name[/b] and [b]CSES resource name[/b]. Once we get the response, we can use some additional PowerShell function like [b]convertfrom-json[/b] 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

 

 

 

[b]The used commands will be: [/b]

 

 

 

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

 

 

 

 

 

largevv2px999.png.eb17fda62a78c3a5c9804c727b4ffbd4.pngExample of REST API request

 

 

 

[size=5][b][b]Sample about how to get OS Family, OS Version and any other data [/b][/b][/size]

 

 

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:

 

largevv2px999.png.5b164e05a95d51a2280d138d8afb375d.pngExample of configuration data of CSES

 

 

 

The $xml is the whole configuration file in XML format. In order to get the data, such as [b]osFamily[/b], [b]osVersion[/b] or [b]VirtualNetworkSite[/b], 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 [b]osVersion[/b]/[b]osFamily[/b], the path to it will be [b]ServiceConfiguration -> osVersion/osFamily[/b]. So the expression to use in PowerShell to get the data will be:

 

 

 

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

 

 

 

mediumvv2px400.png.0556bf839c93920732244776a31ca61a.pngExample 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

 

 

 

largevv2px999.png.e623cf7c5b3c82983e759d48da694dac.pngExample expression of Virtual Network name

 

 

 

[b]Note: [/b]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[[b]1[/b]].Instances.count will be able to return how many instances there are for the [b]second[/b] role.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...