I'm trying to write a script that will give me a list of unused Cloud Services in Azure. Unused, I mean which are stopped or have no deployments.
I figure out how to do it with App Services, but stuck with Cloud Services, because of classic model. I believe it requires different methods to call its properties, etc.
Could someone help me there to dig, or what methods, cmdlets to use to get these properties?
Thanks in advance!
I thought it would have something similar:
function check_site {
Write-Output "------------------------------------------"
Write-Output "Microsoft.Web/sites"
Write-Output "------------------------------------------"
$RT = "Microsoft.Web/sites"
$apps = Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'Microsoft.Web/sites'"
foreach($app in $apps){
$full_app = Get-AzureRmResource -ResourceGroupName $app.ResourceGroupName -ResourceType $RT -ResourceName $app.Name
if("Running" -ne $full_app.Properties.state)
{
$1 = Get-AzureRmResource -ResourceGroupName $app.ResourceGroupName -ResourceType $RT -ResourceName $app.Name | Select-Object -ExpandProperty Name
'App Service: ' + $1
}
}}
For cloud services, you should use Get-AzureService to fetch the details. Then you can use the related properties to determine if it's stopped or not.
If you receive some errors when running this cmdlet, please use Add-AzureAccount
cmdlet first.
The test result: