首页 文章

如何使用Azure资源管理apis按资源类型和资源组获取资源列表

提问于
浏览
1

如何使用Azure Resource Management API获取资源组的资源列表

我已经安装了Microsoft.Azure.Management.ResourceManager.Fluent Nuget包下面的脚本只给出了资源组列表,但没有给出每个资源组的资源列表 .

var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);      
        var azure = Azure.Configure().Authenticate(credentials).WithSubscription(subscriptionID);
        var resourecelist = azure.ResourceGroups.List().ToList();

我正在寻找类似于powershell中可用的东西

Get-AzureRmResource -ResourceGroupName $batchResourceGroup -ResourceType 'Microsoft.Batch/batchAccounts'

1 回答

  • 1

    请尝试使用以下代码获取资源列表 . 我测试它在我身边,它正常工作 . 我们也可以使用Resources - List By Resource Group Rest API来做到这一点 .

    var resouceManagementClient = new ResourceManagementClient(credentials) {SubscriptionId = subscriptionId};
      var resource = resouceManagementClient.ResourceGroups.ListResourcesAsync(resourceGroup,new ODataQuery<GenericResourceFilterInner>(x=>x.ResourceType == "Microsoft.Batch/batchAccounts")).Result;
    

    enter image description here

相关问题