title: How to look for Active Directory group name from csv in PowerShell?
body: <p>If I have a <code>.csv</code>:</p>
  
  <pre><code>ClientCode,GroupCode
  1234,ABC
  1234,DEF
  1235,ABC 
  1236,ABC
  </code></pre>
  
  <p>and I want to get a hashtable with <code>ClientCode</code> as key, and values to be all AD groups with <code>ClientCode</code> in it, for example:</p>
  
  <pre><code>ClientCode GroupCode      
  ---------- ---------      
  1234       ClientGroup_InAD_1234, some_other_client_1234    
  1235       ClientGroup_InAD_1235, some_other_client_in_AD_1235
  1236       ClientGroup_InAD_1236
  </code></pre>
  
  <p>How do I go about this?</p>
  
  <p>Essentially, I have client groups in Active Directory and each client has a code which is the same as the 'ClientCode' in the csv. For example, I might have a client called 'Bob' which I have assigned a code '1234' to it. Therefore, the Group for Bob in the AD would be 'Bob_1234'. Essentially I want to be able to search for whatever groups have ClientCode in them. So i want to search for the all the AD groups that have '1234'. This would return 'Bob_1234' and whatever group in the AD also has '1234' in its name.</p>
  
  <p>So far I have tried:</p>
  
  <pre><code>$clientTable = @{}
  
  foreach($rec in $csv_data) {
      $groups = @(get-adgroup -Filter "name -like '*$($rec.clientcode)_*'")
      write-host "Found $($groups.count) group(s) for: $($rec.clientcode)"
      $clientTable[$ClientCode] = @($groups)
  }
  
  $clientTable
  </code></pre>
  
  <p>but I'm not getting my desired output</p>