#Request Headers required to invoke the GET DEPLOYMENT REST API $method = “GET” $headerDate = ‘2009-10-01’ $headers = @{“x-ms-version”=“$headerDate“}
#Retrieving the subscription ID $subID = (Get-AzureSubscription -Current).SubscriptionId $URI = https://management.core.windows.net/$subID/services/hostedservices/kaushalz/deployments/4f006bb7d2874dd4895f77a97b7938d0
#Retrieving the certificate from Local Store $cert = (Get-ChildItem Cert:\CurrentUser\My | ?{$_.Thumbprint -eq “B4D460D985F1D07A6B9F8BFD67E36BC53A4490FC”}).GetRawCertData()
#converting the raw cert data to BASE64 body = “—–BEGIN CERTIFICATE—–`n</span>$([convert]::ToBase64String($cert))`n—–END CERTIFICATE—–</Binary>” </span>
</p>
#Retrieving the certificate ThumbPrint $mgmtCertThumb = (Get-AzureSubscription -Current).Certificate.Thumbprint
#Passing all the above parameters to Invoke-RestMethod cmdlet Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint ” B4D460D985F1D07A6B9F8BFD67E36BC53A4490FC” -ContentType $ContentType
</td>
</tr>
</table>
</div>
* Launch Windows PowerShell ISE in administrator mode.
* Copy the above sample script and paste it in the scripting window.
NOTE: replace the thumbprint in the above script with the thumbprint of your certificate. You can retrieve this from the MMC windows we accessed earlier. I’m passing the Deployment Name (or Deployment ID) in the above URL.
|
* Run the script to get the output as shown below:
If you read the documentation, the response body is in XML format and it is displaying only the parent node (DEPLOYMENT).
We can read the response into a XML object and then display it. Here is sample snippet:
#Getting the response from the REST API and saving it as a XML object [xml]$url = Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint “B4D460D985F1D07A6B9F8BFD67E36BC53A4490FC” -ContentType $ContentType
#Printing the XML write $url.ChildNodes
|
Below is a screenshot of the output after adding the above two lines in the earlier script:
NOTE: The Configuration section in the above output is a Base-64 encoded string. You would have to add the following snippet to parse this further:
$base64encodedconfiguration = $url.Deployment.Configuration $d= [System.Convert]::FromBase64String($base64encodedconfiguration) [xml]$decodedxml = [System.Text.Encoding]::UTF8.GetString($d) write $decodedxml.ChildNodes
|
You can use the same approach to call any other Azure Service Management REST API. Ensure you read the documentation carefully and then proceed further.
HTH J
|