我需要 power shell 脚本来获取 Azure 中所有应用服务(Web 应用和功能应用)的定价层和应用类型

I need power shell script to get pricing tier and App type of all the App services (Web apps and Function Apps) in Azure

示例: 获取包含定价层和应用类型的应用服务的所有详细信息

下面给出了导出 Web 应用程序详细信息的强大 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 文件如下所示: