title: Connect SQL database with PowerShell and retrieve specific information for an group of users that are stored in variable in PowerShell in CN format
body: <p>I have a script in SQL that returns a bunch of properties in a database using some queries. Among those properties, the <code>PRIMARYOWNER</code> column stores the names of the users in CN format. Like this:</p>
  
  <pre><code>CN=BECALI Gigi (SALES-EXT),OU=Users_CARE,OU=SALES,OU=SALEs,DC=net1,DC=cec,DC=com,DC=int
  </code></pre>
  
  <p>They are connected to other columns which stores in the same SQL database  table other information that I want to be retrieved like <code>DISPLAYNAME, LOGINNAME, OSTYPE, SUITENAME, PUBLISHER, VERSION</code>. </p>
  
  <p>I want to be able to retrieve the software that is installed on specific machines depending on the Department they are from. I am doing this by retrieving the Departments from Active Directory using the following script and storing the results in a variable.</p>
  
  <pre><code>    Clear-Host 
      Import-Module ActiveDirectory
      Write-Host "Processing" 
      $departments = Get-ADUser -Filter * -Property Department |
                     Where-Object { $_.Department } |
                     Select -Expand Department -Unique
  </code></pre>
  
  <p>How do I connect the results from the PowerShell in the CN format with the SQL tables in order to retrieve what software is installed on the specific user in the desired department?</p>