%3CLINGO-SUB%20id%3D%22lingo-sub-824501%22%20slang%3D%22en-US%22%3EHow%20to%20get%20classic%20cloud%20service%20certificates%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824501%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EHow%20to%20get%20classic%20cloud%20service%20certificates%20using%20PowerShell%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHello%20there%2C%20folks!%20I%E2%80%99d%20like%20to%20share%20a%20PowerShell%20script%20which%20can%20be%20helpful%20in%20getting%20the%20cloudservice%20certificates%20by%20calling%20rest%20api.%20Initially%2C%20It%20will%20generate%20the%20bearer%20token%20and%20then%20use%20it%20in%20the%20separate%20api%20to%20get%20the%20certificates%20in%20response.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EPowershell%20Script%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%24ClientID%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22aaaaaaaa-aaa-aaaa-aaaa-aaaaaaaaaaa%22%20%23ApplicationID%3C%2FP%3E%0A%3CP%3E%24ClientSecret%26nbsp%3B%26nbsp%3B%20%3D%20%22eufhdskQkvpjblfkhbpspommbgfm%22%26nbsp%3B%20%23key%20from%20Application%3C%2FP%3E%0A%3CP%3E%24tennantid%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22cccccccc-cccc-cccc-cccc-cccccccccccc%22%3C%2FP%3E%0A%3CP%3E%24SubsciptionID%20%3D%20%225f6161ea-972e-4ce0-94a0-0d5a6ddd210d%22%3C%2FP%3E%0A%3CP%3E%24resourcegroup%20%3D%20%22rg-cloudservice%22%3CBR%20%2F%3E%24cloudservicename%20%3D%20%22dummycloudservice1%22%3C%2FP%3E%0A%3CP%3E%24TokenEndpoint%20%3D%20%7B%3CA%20href%3D%22https%3A%2F%2Flogin.windows.net%2F%7B0%7D%2Foauth2%2Ftoken%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Flogin.windows.net%2F%7B0%7D%2Foauth2%2Ftoken%3C%2FA%3E%7D%20-f%20%24tennantid%3C%2FP%3E%0A%3CP%3E%24Resource%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fmanagement.core.windows.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fmanagement.core.windows.net%2F%3C%2FA%3E%22%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24Body%20%3D%20%40%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'resource'%3D%20%24Resource%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'client_id'%20%3D%20%24ClientID%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'grant_type'%20%3D%20'client_credentials'%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'client_secret'%20%3D%20%24ClientSecret%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24params%20%3D%20%40%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ContentType%20%3D%20'application%2Fx-www-form-urlencoded'%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Headers%20%3D%20%40%7B'accept'%3D'application%2Fjson'%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Body%20%3D%20%24Body%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Method%20%3D%20'Post'%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20URI%20%3D%20%24TokenEndpoint%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24token%20%3D%20Invoke-RestMethod%20%40params%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24headerParams%20%3D%20%40%7B'Authorization'%3D%22%24(%24token.token_type)%20%24(%24token.Access_Token)%22%7D%3C%2FP%3E%0A%3CP%3E%24uri%20%3D%20'https%3A%2F%2F'%20%2B%20's2.cloudservices.ext.azure.com%2Fapi%2FCertificates%3FapiVersion%3D2016-12-01%26amp%3BresourcePath%3D%2Fsubscriptions%2F'%2B%24SubsciptionID%2B'%2FresourceGroups%2F'%2B%20%24resourcegroup%20%2B'%2Fproviders%2FMicrosoft.ClassicCompute%2FdomainNames%2F'%2B%20%24cloudservicename%20%2B'%2FserviceCertificates%3Fapi-version%3D2015-06-01'%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EInvoke-RestMethod%20-Method%20Get%20-Headers%20%24headerParams%20-Uri%20%24uri%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20output%2C%20you%20will%20get%20the%20certificate%20in%20response%20(see%20example%20below).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22clipboard_image_0.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128709i3F85875E936B6991%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22clipboard_image_0.png%22%20alt%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
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