title: How to read txt/csv line by line using PowerShell
body: <p>I have a couple of txt/csv files, I am trying to feed the each line in the file into my API commands in a loop.</p>
  
  <p>eg: server.txt - first file contains servers and resource groups <code>server1, rg1
                                                            server2, rg2
                                                            server3, rg3</code> etc.</p>
  
  <p>ips.txt - another file contains rules &amp; ips <code>rule1, startip1, endip1
                                        rule2, startip2, endip2
                                        rule3, startip3, endip3</code> etc.</p>
  
  <p>The issue is how to I set up powershell to each line in server.txt and also ips.txt within the same loop?</p>
  
  <p>I had something like this before, but It doesnt seem to work well. Any thoughts?</p>
  
  <pre><code>$list=Get-Content "servers.txt"
  
  foreach ($data in $list) {
      $server_name, $rg = $data -split ',' -replace '^\s*|\s*$'
  
  
      Write-Host "Checking if SQL server belongs in subscription"
      $check=$(az sql server list -g $rg --query "[?name == '$server_name'].name" -o tsv)
      Write-Host $check
  
  
      # Get current rules and redirect output to file
      az sql server firewall-rule list --resource-group "$rg" --server "$server_name" --output table | Export-Csv -NoTypeInformation current-natrules.csv
  
      $new_rules=Get-Content "ips.txt"
  
      foreach ($data in $new_rules) {
          $rule_name, $start_ip, $end_ip = $data -split ',' -replace '^\s*|\s*$'
  
          # Create rule with new configs
          Write-Host "Assigning new firewall rules..."
          az sql server firewall-rule create --name "$rule_name" --server "$server_name" --resource-group "$rg" --start-ip-address "$start_ip" --end-ip-address "$end_ip" --output table
      }
  
      # Validating
      Write-Host "Printing new NAT rules to file..."
      az sql server firewall-rule list --resource-group "$rg" --server "$server_name" --output table | Export-Csv -NoTypeInformation new-natrules.csv
  }
  </code></pre>