0

I'm trying to invoke Azure REST API from Powershell to start/stop a classic service.

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($token.Token)")
$headers.Add("Content-Type", "application/json") 
$response = Invoke-RestMethod "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$rscGrp/providers/Microsoft.ClassicCompute/domainNames/$serviceName/slots/production/$action?api-version=2020-02-01" -Method 'POST' -Headers $headers
$response | ConvertTo-Json

When $action="start", the command works perfectly and the service starts all instances as required. However, when $action="stop", the command deletes the whole service all together. The whole deployment slot is deleted instead of simply stopping the instances. Basically, I want it to behave exactly like clicking on the "stop" button in Azure Portal.

Ahmad Masalha
  • 379
  • 2
  • 9

2 Answers2

0

You can use this Rest API, to Power off the cloud service. Note that resources are still attached and you are getting charged for the resources

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}/poweroff?api-version=2021-03-01
VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
0

It looks like you're referencing a classic cloud service. I'm not sure how it translates to the management.azure.com endpoint, but on the old https://management.core.windows.net endpoint, I believe you're looking for Update Deployment Status with a desire to set the status to "Suspended".

The behavior is the same as the other answer specified for the Microsoft.Compute/cloudServices respirce: the roles will stop, but you will still be charged for them.

Greg D
  • 43,259
  • 14
  • 84
  • 117