title: Remove group memberships from users who are disabled
body: <p>I'm trying to write a script to find disabled users that is member of one or more groups in a specific OU in AD. It will then remove all the groups for all the disabled users. But I want to generate a list of users, with the exception of a list of names. Lets say I dont want to remove groups for some specific disabled users.</p>
  
  <pre><code>$SearchBase = "OU=Disabled Users,DC=contoso,DC=com"
  $Users = Get-ADUser -filter * -SearchBase $SearchBase -Properties MemberOf
  $ExcludeUsers =@("SM_82786dfdc96642ed9","SM_516a93b689334db1a")
  $Users = $Users | where-Object { $ExcludeUsers -notcontains $_.samaccountname }
  ForEach($User in $Users){
  $User.MemberOf | Remove-ADGroupMember -Member $User -Confirm:$false
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Remove-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
  At line:3 char:22
  +     $User.MemberOf | Remove-ADGroupMember -Member $User -Confirm:$false
  +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidData: (:) [Remove-ADGroupMember], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.RemoveADGroupMember
  </code></pre>