Cloud Service (extended support) management via PowerShell

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

In the CSES world, users usually need to manage cloud service (extended support) via PowerShell, since some management operations are not available in portal so far. This blog provides some common samples to manage cloud service (extended support) resources by PowerShell. 

 

Following perspectives will be introduced in this blog: 

  • Environment preparation 
  • CSES creation via PowerShell   
  • CSES updating via PowerShell   
  • Enable CSES RDP extension via PowerShell 

 

  • Prepare environment 
  • If engineers or customers encounter similar following error, it may be because the module isnot successfully installed or there is some issue with this version of module. We can install/uninstall the Az module. 

    • Install-Module -Name Az
    • Uninstall-Module -Name Az -AllVersions

Reference doc:  

Install the Azure Az PowerShell module | Microsoft Docs 

Uninstall Azure PowerShell | Microsoft Docs 

 

  • Create a new cloud service (extended support) 
    • Create CSES with local files.
      $cspkgFilePath ="C:\SE\Cloudservice\cses-cscfgfile.cspkg" $cscfgFilePath = "C:\SE\Cloudservice\cses-cscfgfile.cscfg" $csdefFilePath = "C:\SE\Cloudservice\cses-csdeffile.csdef" $storageAccount= "storageacc4cses" # Create Cloud Service New-AzCloudService -Name "blog2ps-cses2" -ResourceGroupName "cloudservice2-Migrated" -Location "WestUS" -ConfigurationFile $cscfgFilePath -DefinitionFile $csdefFilePath -PackageFile $cspkgFilePath -StorageAccount $storageAccount
    • Create CSES with cspkg file from the storage account
      $cspkgUrl = "cspkg SAS URL" $cscfgFilePath = "C:\SE\Cloudservice\cses-cscfgfile.cscfg" $csdefFilePath = "C:\SE\Cloudservice\cses-csdeffile.csdef" New-AzCloudService -Name "blog2ps-cses2" -ResourceGroupName "cloudservice2-Migrated" -Location "WestUS" -ConfigurationFile $cscfgFilePath -DefinitionFile $csdefFilePath -PackageUrl $cspkgUrl

Note: 

In the Azure portal, you can generate SAS URL from the storage account container. 

yiyang2_0-1635426044269.png

Important: 

  • Make sure the cscfg file you used can match the csdef in the cspkg file. Even when you meet the following message, it still may because you use the unmatched files. .
    Az.CloudService\New-AzCloudService : The CSCFG could not be parsed. Please use the documentation at https://aka.ms/cses-cscfg-schema for CSCFG schema details. More details: Top-level XML element does not conform to schema
  • Except the above two samples, you can use the New-AzCloudService command with different groups of parameters. And you need to make sure that the pair of parameters is correct. Such like when you use the local file to create the CSES, the -StorageAccount is necessary. You can check the parameters pairs in the second reference documentation.   

Reference doc:  

Deploy a Cloud Service (extended support) - PowerShell | Microsoft Docs 

New-AzCloudService (Az.CloudService) | Microsoft Docs 

 

  • Update config file of existing cloud service (extended support)
    $cloudServiceName="csesportal" $resourceGroupName="CLOUDSERVICE2-MIGRATED" $cspkgUrl = "cspkg SAS URL" $cscfgContent='configuration file content' $cloudService = Get-AzCloudService -Name $cloudServiceName -ResourceGroupName $resourceGroupName $cloudService.PackageUrl = $cspkgUrl $cloudService.Configuration = $cscfgContent $cloudService | Update-AzCloudService

Important:

  • Make sure you use the cscfg file which can match the cscdef in the cspfk file. 

Note:

  • Sample for value of $cscfgContent $cscfgContent='<ServiceConfiguration serviceName="cses" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6"> <Role name="WebRole1"> <Instances count="1" /> <ConfigurationSettings> <Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="133f35ff-efad-4518-9f8b-6a7f7b1438e1" /> </ConfigurationSettings> </Role> <NetworkConfiguration> <VirtualNetworkSite name="VNet-cloudservice2" /> <AddressAssignments> <InstanceAddress roleName="WebRole1"> <Subnets> <Subnet name="DefaultVNetSubnet" /> </Subnets> </InstanceAddress> </AddressAssignments> </NetworkConfiguration> </ServiceConfiguration>'

Reference doc: 

Update-AzCloudService (Az.CloudService) | Microsoft Docs 

 

  • Enable extension on the cloud service (extended support) 
    • Enable the Remote Desktop extension .
      # Create new RDP extension object $credential = Get-Credential $expiration='10/30/2021' $rdpExtension = New-AzCloudServiceRemoteDesktopExtensionObject -Name "RDPextension" -Credential $credential -Expiration $expiration -TypeHandlerVersion "1.2.1" $cloudService = Get-AzCloudService -ResourceGroup "CLOUDSERVICE2-MIGRATED" -CloudServiceName "csesportal" # Add RDP extension to existing cloud service extension object $cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension + $rdpExtension # Update cloud service $cloudService | Update-AzCloudService

Reference doc: 

Apply the Windows Azure diagnostics extension in Cloud Services (extended support) | Microsoft Docs 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.