title: Powershell Loop though specific json files from multiple folders and use that json file to push into Loop
body: <pre><code>$tenantID = (Get-AzureADTenantDetail).ObjectId
  $mg = &quot;/providers/Microsoft.Management/managementGroups/&quot; + $tenantID
  
  foreach($subfolder in Get-ChildItem -Path C:\Users\xxxx\Desktop\AzurePolicies -Depth 2 -Recurse){
      Write-Host &quot;Subfolder is &quot; $subfolder
      foreach($file in Get-ChildItem -Path $subfolder -File *.json -Recurse){
          foreach($policy in $file){
              $displayname = (Get-Content $file -Raw | ConvertFrom-Json).properties.displayName
              Write-Host &quot;Display name is&quot; $displayname
              $policyname = (Get-Content $policy -Raw | ConvertFrom-Json).properties.name
              Write-Host &quot;Policy name is&quot; $policyname
              foreach ($item in $policy) {
                  function DefinePolicies {
                      New-AzPolicyDefinition -Name $policyname -DisplayName $displayname -Policy $policy   -ManagementGroupName $tenantID
                      Start-Sleep -Seconds 2
                  }
                  DefinePolicies
                  function AssignPolicies {
                      $policy = Get-AzPolicyDefinition -Name $policyname  -ManagementGroupName $tenantID
                      New-AzPolicyAssignment -Name $policyname -PolicyDefinition $policy -Scope $mg
                       Start-Sleep -Seconds 2
                  }
                  AssignPolicies
              }   
              }
      }
  }    
  </code></pre>
  <p>My Files are organized as Azurepolicies/Keyvaults/Somepolicy/azurepolicy.json</p>