locked
Remove-ADGroupMember from groups imported from csv with names like... RRS feed

  • Question

  • Hello,

    I am trying to import a list of ADGroups and remove members whose name are like "eXXX" or "cXXX" (for example).

    Very simple to remove all members from a list of imported groups but I am struggling on how to incorporate a ? {(Name -Like "eXXX*") -or (Name -Like "cXXX*")} following the -Members parameter. 

    Perhaps I am missing something simple but any help would be appreciated.

    Tuesday, September 1, 2015 2:41 PM

Answers

  • Something like this:


    Remove-ADGroupMember -Identity $_.group -Members (Get-ADGroupMember -Identity $_.group | Where { $_.Name -like 'e*' -or $_.Name -like 'c*' }) -Confirm:$false -WhatIf



    Tuesday, September 1, 2015 3:20 PM

All replies

  • try something like this;

    Where-Object {$_.Name -like "e*" -or $_.Name -like "c*"}

    Hope this helps


    Cheers, Matthew Kerfoot

    • Proposed as answer by Mike Laughlin Tuesday, September 1, 2015 3:29 PM
    Tuesday, September 1, 2015 2:54 PM
  • Where would I tie that into the... 
    Remove-ADGroupMember -Identity $_.group -Members

    Tuesday, September 1, 2015 3:01 PM
  • Something like this:


    Remove-ADGroupMember -Identity $_.group -Members (Get-ADGroupMember -Identity $_.group | Where { $_.Name -like 'e*' -or $_.Name -like 'c*' }) -Confirm:$false -WhatIf



    Tuesday, September 1, 2015 3:20 PM
  • You rock sir... thank you kindly
    Tuesday, September 1, 2015 3:28 PM
  • Cheers, you're welcome.

    Tuesday, September 1, 2015 3:29 PM