How to get classic cloud service certificates using powershell

Published Aug 27 2019 05:55 AM 1,755 Views
Microsoft

How to get classic cloud service certificates using PowerShell

 

Hello there, folks! I’d like to share a PowerShell script which can be helpful in getting the cloudservice certificates by calling rest api. Initially, It will generate the bearer token and then use it in the separate api to get the certificates in response.

 

Powershell Script

$ClientID       = "aaaaaaaa-aaa-aaaa-aaaa-aaaaaaaaaaa" #ApplicationID

$ClientSecret   = "eufhdskQkvpjblfkhbpspommbgfm"  #key from Application

$tennantid      = "cccccccc-cccc-cccc-cccc-cccccccccccc"

$SubsciptionID = "5f6161ea-972e-4ce0-94a0-0d5a6ddd210d"

$resourcegroup = "rg-cloudservice"
$cloudservicename = "dummycloudservice1"

$TokenEndpoint = {https://login.windows.net/{0}/oauth2/token} -f $tennantid

$Resource = "https://management.core.windows.net/";

 

$Body = @{

        'resource'= $Resource

        'client_id' = $ClientID

        'grant_type' = 'client_credentials'

        'client_secret' = $ClientSecret

}

 

$params = @{

    ContentType = 'application/x-www-form-urlencoded'

    Headers = @{'accept'='application/json'}

    Body = $Body

    Method = 'Post'

    URI = $TokenEndpoint

}

 

$token = Invoke-RestMethod @params

 

$headerParams = @{'Authorization'="$($token.token_type) $($token.Access_Token)"}

$uri = 'https://' + 's2.cloudservices.ext.azure.com/api/Certificates?apiVersion=2016-12-01&resourcePath=/subscriptions/'+$SubsciptionID+'/resourceGroups/'+ $resourcegroup +'/providers/Microsoft.ClassicCompute/domainNames/'+ $cloudservicename +'/serviceCertificates?api-version=2015-06-01'

 

Invoke-RestMethod -Method Get -Headers $headerParams -Uri $uri

 

In output, you will get the certificate in response (see example below).

 

clipboard_image_0.png

 

Version history
Last update:
‎Sep 15 2020 07:31 AM
Updated by: