Tuesday, January 17, 2017

Delete/List Disabled Extensions from the Cloud Service.

There are 2 steps to delete/List Disabled Cloud Service Extensions from the Cloud Service.
  •  Self-Signing Certificate

a.       Create Certificate on Local machine.
b.      Upload Certificate on Classic Azure Portal.

  •  Run Rest API Call to Delete/List Disabled Extensions from the service.

a.       List all disabled Extensions from the service.

b.      Delete All Disabled Extension from the Service.

1.      Self-Signing Certificate :
Self-signing Certificate will is the identity of the signer. That is who is creating this certificate. This is signed with your own private key to identify you.

a.      Create Self-Signing Certificate : (Credit Courtenay Bernier - Bog Link )

To create certificate you need to have makecert.exe installed on your machine.
Once makecert.exe is installed on the machine you will connect to Windows Azure with, open a command prompt. The command prompt may default to PowerShell, at the prompt type in “cmd” to access Windows Shell scripting console.
Copy and paste the following to your favorite text editor and save as a .cmd file (pick any file name you like).

@echo off
echo This script will create an Azure certificate and export for use in Windows Azure.
echo.
echo Computer Name
echo %computername%
echo.
echo creating folder: %SystemDrive%\certs
mkdir %SystemDrive%\certs
%SystemDrive%
cd certs
echo.
dir "C:\Program Files (x86)\Windows Kits\8.1\bin\x64" | findstr /i "makecert.exe"
IF ERRORLEVEL = 1 GOTO ERROR
IF ERRORLEVEL = 0 GOTO CreateCert
echo.
:CreateCert
echo creating cert and placing it in %SystemDrive%\certs
echo.
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\makecert.exe" -r -pe -n CN=%computername%-AzureCert -ss my -sr localmachine -eku 1.3.6.1.5.5.7.3.2 -len 2048 -e 01/01/2016 %computername%-AzureCert.cer
echo.
echo.
goto end
:ERROR
echo makecert.exe file not found. Please check directory path above or download and install the Windows 8.1 SDK from http://www.microsoft.com/click/services/Redirect2.ashx?CR_EAC=300135395
goto end
:end

Run the script from the command prompt:

Certificate is in your \cert folder. Open the MMC and add the Certificate add in for the local computer:

a.      Upload Certificate on Classic Azure Portal.
Login to Azure Classic Portal, https://manage.windowsazure.com. Go to Settings -> MANAGEMENT CERTIFICATES Tab.
Upload select the certificate you created and copy the thumbprint and save it somewhere. We will need it later on.


2.       Run Rest API Call to Delete/List Disabled Extensions from the service.

To LIST/DELETE you need to call rest API. This done through Power-Shell. For both calls you need to setup the account to the Power-Shell.  Run Power-Shell with Admin mode and Run the following command.  This will open Popup asking for your azure login credentials.
          
  Add-AzureAccount

On Successful login this will show your subscription id and other details.

a.       List all Disabled Extensions.

$method = "GET"
$headerDate = '2017-17-01'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-ms-version","$headerDate")
$subID = (Get-AzureSubscription -Current).SubscriptionId
$CloudServiceName = "serviceNameHere"

$URI = "https://management.core.windows.net/$subID/services/hostedservices/$CloudServiceName/extensions"

$url = Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint "Thumb print pest here"

 Write-Output $url.Extensions.Extension  



a.       DELETE all Disabled Extensions.

$method = "DELETE"
$headerDate = '2017-17-01'
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-ms-version","$headerDate")
$subID = (Get-AzureSubscription -Current).SubscriptionId
$CloudServiceName = "serviceNameHere"

$URI = "https://management.core.windows.net/$subID/services/hostedservices/$CloudServiceName/extensions"

$url = Invoke-RestMethod -Uri $URI -Method $method -Headers $headers -CertificateThumbprint "Thumb print pest here"

 Write-Output $url.Extensions.Extension   



Useful Links:


For your future reference and in addition to earlier notes, I am mentioning here a few articles. Please note that these articles may or may not be related to your current case, but good pointers for keeping them in your record book for future reference.



No comments:

Post a Comment