title: Multiple ForEach with Arrays in Powershell
body: <p>I am trying to generate two data files (first for each) and generate just one document to each file (second for each). I can generate the two data files just fine, however, it creates 2 documents and assigns it to each file. I just need it to assign one document to one file, then the other document to another file. I've struggled and haven't been able to come up with a solution (novice developer). What can I do to accomplish this?</p>
  
  <pre><code>$filepath="C:\files\pdf\"
  $data_files = Get-ChildItem $filepath
  $filesss=$data_files | Write-Output
  
  $Data2= $filesss -split "`n"
  $i2=0
  $var=@()
  
  $gravy= Get-Content "C:\files\temp.txt"
  $ia=0
  $data44=@()
  
  
  foreach  ($item2 in $Data2)
           {
  
            $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
            $headers.Add("Accept", 'application/pdf')
  
            $fileName="C:\files\pdf\$item2"
            $fileContent = get-content -Raw $fileName
            $fileContentBytes = [System.Text.Encoding]::Default.GetBytes($fileContent)
            $fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
  
  
  
  foreach($id in $gravy){
  
                          $data44= ConvertTo-Json @{
                               encrypted="false";
                               allowSaveBinaryData="true";
                               binaryData="$fileContentEncoded"
                               divider="Expense Report";
                               extension="pdf";
                               name="$fileContentEncoded";
                               relProjectId="31";
                              }
  
             $var2[$i2]="https://XXXXXXX.com/v4/documents/$id/?guid=$AUTHtemp&amp;fbsite=https://API/"
  
             Invoke-RestMethod -headers $headers -ContentType 'application/json' -Method PUT -body $data44 -Uri $var2 
  
             $ia++
                         }
  $i2++ }
  </code></pre>