title: How can I loop through OU in AD to add users to various security groups?
body: <p>I'm somewhat new to writing PS scripts, I usually only need simple one or two liners, but for this I'm trying to loop through a specific OU in Active Directory to find each users department, add "grp" before it and add them to the security group by that name.  For example, a department might be something like 10005 so I'd like to add them to security group named "grp10005".  Here's what I have but it isn't working.</p>
  
  <pre><code>Import-Module ActiveDirectory  
  
   $users = $i = $null  
   $strCC
   $strGRP = 'grp' &amp; strCC
  
   $users = Get-ADUser -SearchBase "ou=Test,ou=OurUsers,ou=Logins,dc=domain,dc=com" -filter * {department -eq $strCC}  
   ForEach($user in $users)  
      {    
        Add-ADGroupMember 'strGRP' -Members $_.DistinguishedName
          -ErrorAction SilentlyContinue
        $i++  
      }  
  </code></pre>