示例:通过定价层和应用类型获取应用服务的所有详细信息
下面给出了用于导出Web应用程序详细信息的Power Shell脚本,但是我无法获取应用程序服务的定价层和应用程序类型。
#Provide the subscription Id where the Webapps ,function apps resides
$subscriptionId = "XXXXXXXXXXXXXXXXXXXXXXX"
$currentTime=$(get-date).ToString("yyyyMMddHHmmss");
$outputFilePath=".\AzureWebAppsReport-"+$currentTime+".csv"
Set-AzureRmContext $subscriptionId
$result=@()
# Get all the webapps
$webapps =Get-AzureRMWebApp
$AzSubscription = Get-AzureRmSubscription -SubscriptionId $subscriptionId
$rmresources = Get-AzureRmResource | ?{ $_.Sku -NE $null}
# Loop through the webapps
foreach($webapp in $webapps)
{
$info = "" | Select Name,State,LOCATION,ResourceGroup,SUBSCRIPTION,AppServicePlan,PricingTier
foreach($rmResource in $rmresources) {
if($webapp.ResourceGroup -eq $rmResource.ResourceGroupName) {
$info.PricingTier = $rmResource.Sku
}
}
$info.Name = $webapp.Name
$info.State = $webapp.State
$info.LOCATION = $webapp.LOCATION
$info.ResourceGroup = $webapp.ResourceGroup
$info.SUBSCRIPTION = $AzSubscription.Name
$info.AppServicePlan=$webapp.ServerFarmId
#Add the object with above properties to the Array
$result+=$info
}
$result | ft Name,State,LOCATION,ResourceGroup,SUBSCRIPTION,AppServicePlan,PricingTier
#Export the result Array to CSV file
$result | Export-CSV $outputFilePath -NoTypeInformation
您可以在下面尝试我的示例,它对我而言效果很好。
$AzSubscription = Get-AzSubscription -SubscriptionId "<subscription-id>"
$result=@()
$webapps = Get-AzWebApp
foreach($webapp in $webapps){
$Tier = (Get-AzResource -ResourceId $webapp.ServerFarmId).Sku.Tier
$obj = [PSCustomObject]@{
Name = $webapp.Name
State = $webapp.State
Location = $webapp.Location
PricingTier = $Tier
AppType = $webapp.Kind
ResourceGroup = $webapp.ResourceGroup
Subscription = $AzSubscription.Name
}
$result += $obj
}
$result | Export-Csv -Path "C:\Users\joyw\Desktop\webapps.csv" -NoTypeInformation
.csv
文件将如下所示: