[英]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.我正在尝试编写一个脚本,该脚本将为我提供 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?有人可以帮我挖掘,或者使用什么方法,cmdlet 来获取这些属性?
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.对于云服务,您应该使用Get-AzureService来获取详细信息。 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.如果在运行此 cmdlet 时收到一些错误,请先使用
Add-AzureAccount
cmdlet。
The test result:测试结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.