title: If And statement with a foreach for AD Users in Powershell
body: <pre><code>$names = Import-CSV C:\PowerShell\TerminatedEmployees.csv
  $Date = Get-Date
  foreach ($name in $names) 
  {
      Get-ADPrincipalGroupMembership -Identity "$($name.TextBox37)" | select Name | Out-File "C:\Powershell\ADUserMemberships\$($name.TextBox37)Memberships.txt"
      $ADgroups = Get-ADPrincipalGroupMembership -Identity "$($name.TextBox37)" | where {$_.Name -ne "Domain Users"}
      Remove-ADPrincipalGroupMembership -Identity "$($name.TextBox37)" -MemberOf $ADgroups -Confirm:$false
      Disable-ADAccount -Identity "$($name.TextBox37)"
      Get-ADUser -Identity "$($name.TextBox37)" | Move-ADObject -TargetPath "OU=DisabledAccounts,OU=XXX,DC=XXX,DC=XXXX,DC=XXX"
      Set-ADUser -Identity "$($name.TextBox37)" -Description "Disabled $Date"
  }
  </code></pre>
  
  <p>This is an already working script I have.  However, I realized I need to check 2 properties on the AD user to determine if they need to need to go through my foreach statement.  Both properties need to be met.  If they are then there's no reason for the AD users to be processed.</p>
  
  <ol>
  <li><p>The AD user is already disabled.</p></li>
  <li><p>The AD user already resides in the Disabled OU.</p></li>
  </ol>
  
  <p>I'm thinking this needs to be done in an If -And statement.  But does this need to be done before the foreach or inside the foreach?  </p>