text: /*
   * Copyright (c) Microsoft Corporation.
   * Licensed under the MIT License.
   *
   * Code generated by Microsoft (R) AutoRest Code Generator.
   * Changes may cause incorrect behavior and will be lost if the code is regenerated.
   */
  
  // Copyright (c) Microsoft Corporation.
  // Licensed under the MIT License.
  /**
   * This sample demonstrates how to Queries policy states for the resource.
   *
   * @summary Queries policy states for the resource.
   * x-ms-original-file: specification/policyinsights/resource-manager/Microsoft.PolicyInsights/stable/2019-10-01/examples/PolicyStates_QuerySubscriptionLevelNestedResourceScope.json
   */
  const { PolicyInsightsClient } = require("@azure/arm-policyinsights");
  const { DefaultAzureCredential } = require("@azure/identity");
  
  async function queryAllPolicyStatesAtSubscriptionLevelNestedResourceScope() {
    const subscriptionId = "00000000-0000-0000-0000-000000000000";
    const policyStatesResource = "default";
    const resourceId =
      "subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/providers/Microsoft.SomeNamespace/someResourceType/someResource/someNestedResourceType/someNestedResource";
    const credential = new DefaultAzureCredential();
    const client = new PolicyInsightsClient(credential, subscriptionId);
    const resArray = new Array();
    for await (let item of client.policyStates.listQueryResultsForResource(
      policyStatesResource,
      resourceId
    )) {
      resArray.push(item);
    }
    console.log(resArray);
  }
  
  queryAllPolicyStatesAtSubscriptionLevelNestedResourceScope().catch(console.error);
  