title: Get output from PowerShell being called by Python to be formatted like a CSV file so I can take output and put into SQL table
body: <p>new to coding, self-learning and googling a lot, but cannot find an answer specific to what I am trying to do. I will try my best to describe what I am trying to do, please let me know if you need more clarification.</p>
  <p>Here is the code I am running to have python execute a PowerShell command and return with (3) columns of data: Application Name, Vendor, Version:</p>
  <pre><code>import subprocess
  import sys
  import ServerListScript
  
  PSScriptInstalledPrograms = &quot;&quot;&quot;Invoke-Command -ComputerName %s -ScriptBlock {
  cmd.exe /c &quot;wmic product where `&quot;not name like '%%Windows%%' and not name like '%%Microsoft%%'`&quot; get name, vendor, version&quot;}&quot;&quot;&quot;
  
  ListOfServers = ServerListScript.ListOfServers
  server_list = ListOfServers
  
  for server_name in server_list:
          print(PSScriptInstalledPrograms %(server_name))
          p = subprocess.run([
              &quot;powershell.exe&quot;,
              &quot;-command&quot;,
              PSScriptInstalledPrograms %(server_name)
          ],
          stdout=sys.stdout)
          #stdout=sys.stdout.write('\n'))
          print('Finished Processing')
  </code></pre>
  <p><strong>The ask for help part:</strong>
  What I'd like to do is to be able to take the return from Powershell and make it a CSV (or something similar) that would then be easy to put into a list  and use that list to populate a table in SQL, similar to the below (that writes the results of another python function that queries a SQL server for other results). I suspect a couple of things right off the start:</p>
  <ol>
  <li>The return from PowerShell <em>looks</em> like a list, but is actually just displayed that way - I think that it is actually a bunch of words separated by a space and/or new line, but aren't individual items in a list; hard to explain what I mean, like the difference between:</li>
  </ol>
  <p><strong>['Col1 row1 Col2 row1 Col3 row1 Col1  row2 Col2 row2 Col3 row2']</strong></p>
  <p>vs.</p>
  <p><strong>['Col1 row1'], ['Col2 row1'], ['Col3 row1'], ['Col1 row2'],['Col2 row2'],['Col3 row2']</strong></p>
  <p>I hope that makes sense?</p>
  <ol start="2">
  <li>I am using <code>stdout</code> - but I don't know if what I am getting from the PowerShell return is actually being stored as something I can 'grab' and push somewhere else (as noted in my write to SQL table function below)</li>
  </ol>
  <pre><code>##Function for writing to SQL table for audit
  def WriteAllMatches():
      print(&quot;Writing to [Job_Status_DB].[dbo].[Server_DB_Audit]&quot;)
      connection = pyodbc.connect('Driver={%s};'
                                  'Server=MYSERVER.DOMAIN.COM;'
                                  'Database=Master;'
                                  'uid=%s;'
                                  'trusted_connection=yes' % (Driver, domain_user), timeout=4)
      cursor = connection.cursor();
      print(&quot;############### Writing Data To Table ###############&quot;)
      output = cursor.executemany(&quot;&quot;&quot;INSERT INTO [Audit_DB].[dbo].[Server_App_Audit]
                              (Server_Name,App_Name,App_Vendor,App_Version) VALUES(?,?,?,?)&quot;&quot;&quot;,
                                  AllProceedureData);
      values = [AllProceedureData]
      print(AllProceedureData)
      for row in AllProceedureData:
          print(row)
      connection.commit();
      cursor.close();
      connection.close();
  </code></pre>
  <p>I know that the function for writing to a SQL table for my audit will have to be modified, I just wanted to provide as much detail as possible. Also, all the print statements are for me to help figure out/understand what my code is doing (iterative approach) as I am going through this. They will <em>probably</em> be removed on the finished version.</p>
  <p>Any help/guidance is appreciated - I am loving learning, but there are somethings that, while I can wrap my head around what I want to do, I can't seem to execute on. Please be patient with me - I spent 17 of the last 22 years being a telecom engineer and designing networks to making an attempt to learn coding/automation.</p>