Windows Azure Pack PowerShell sample commands – Remove Commands

Windows Azure Pack PowerShell sample commands – Remove Commands

To close out the series of the simple sample commands for Azure Pack the first being to Get the Second to Add and this one will go over the process of Removing objects from Azure Pack. Much like the first two posts the first 33 lines are the same which obtains the connection details for your Azure Pack environment, along with an authentication token.

Once we have obtained these details we will have the starting point to remove each of the objects we created in the second blog post, this needs to be completed in reverse where the Subscription is required to be removed before the Plan can be removed. Once both have been removed then the User object can be removed.

You will note that for both the subscription and the plan we need to obtain the Subscription ID and Plan ID respectively. Rather than typing these in I have added the command to obtain it from the name of the Subscription and the Plan.

# query SQL function

function Invoke-SQL {

param([string] $connstring,[string] $sqlCommand)

$connectionString = $connstring

$connection = new-object system.data.SqlClient.SQLConnection($connectionString)

$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)

$connection.Open()

$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command

$dataset = New-Object System.Data.DataSet

$adapter.Fill($dataSet) | Out-Null

$connection.Close()

$dataSet.Tables

}

 

# get WAP connection string

$connstring = (Get-MgmtSvcSetting -Namespace adminsite | where {$_.name -eq ‘ApplicationServicesConnectionstring’}).value

$connstring = $connstring.Split(‘;’)[0] + ‘;’ + $connstring.Split(‘;’)[1] + “; Integrated Security=SSPI”

 

# get WAP websites

$adminsite = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘AdminSite’ and Name = ‘Authentication.Fqdn'” -connstring $connstring).value

$TenantSite = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘TenantSite’ and Name = ‘Authentication.Fqdn'” -connstring $connstring).value

$AuthSite = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘AuthSite’ and Name = ‘Authentication.Fqdn'” -connstring $connstring).value

$windowsauthsite = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘WindowsAuthSite’ and Name = ‘Authentication.Fqdn'” -connstring $connstring).value

$AdminAPI = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘AdminSite’ and Name = ‘Microsoft.Azure.Portal.Configuration.OnPremPortalConfiguration.RdfeAdminUri'” -connstring $connstring).value

$TenantAPI = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘TenantSite’ and Name = ‘Microsoft.Azure.Portal.Configuration.AppManagementConfiguration.RdfeUnifiedManagementServiceUri'” -connstring $connstring).value

$ClientRealm = (Invoke-SQL -sqlCommand “SELECT value FROM [Config].[Settings] where Namespace = ‘AdminSite’ and Name = ‘Authentication.RelyingParty'” -connstring $connstring).value.Split(‘,’)[1].replace(‘”Realm”:”‘,).replace(‘”‘,)

 

# Check is cert is signed

$admin = $adminsite.Split(‘:’)

$cert = !(New-Object System.Net.Security.SslStream((New-Object System.Net.Sockets.TcpClient($admin[1].Replace(‘/’,),$admin[2])).GetStream())).IsSigned

 

# get token

$token = Get-MgmtSvcToken -AuthenticationSite $windowsauthsite -ClientRealm $ClientRealm -Type Windows -DisableCertificateValidation:$cert

 

# Remove Subscription

$SubscriptionName = ‘Steve’

$subscriptionID = (Get-MgmtSvcSubscription -AdminUri $AdminAPI -Token $token -DisableCertificateValidation:$cert | Where-Object {$_.SubscriptionName -eq $SubscriptionName}).SubscriptionID

Remove-MgmtSvcSubscription -AdminUri $AdminAPI -Token $token -DisableCertificateValidation:$cert -SubscriptionId $subscriptionID

 

# remove Plan

$planName = ‘steve’

$planid = (Get-MgmtSvcPlan -AdminUri $adminapi -Token $token -DisableCertificateValidation:$cert -DisplayName $planName).id

Remove-MgmtSvcPlan -AdminUri $AdminAPI -Token $token -DisableCertificateValidation:$cert -PlanId $planid

 

# remove User

$name = ‘Steve’

Remove-MgmtSvcUser -AdminUri $adminapi -Token $token -DisableCertificateValidation:$cert -Name $name

This concludes the Blog posts on the Simple administrative tasks for Azure Pack, if you have followed each of the blogs that we have found, created and deleted each of the 3 object types, but once the Subscription is associated to a user there are no resources allocated to it. In the next group of Blog posts we will go over the process to allocate resources to the Plan/Subscription. But until then.

Good Luck.

Steve

Leave a Reply