简体   繁体   中英

Find all Cloud Services (Classic) which are stopped or have no deployments

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM