title: Remove domain group for Local Administrators using wild card
body: <p>I am trying to clean up the local administrators group on some machines and need a solution in Powershell. So far I've managed to retrieve the list of members but I'm having trouble with my syntax to find the group I want to remove. The group on each machine that needs removal will be different but does have the same name format.</p>
  
  <p>I could use this if the group name was the same:</p>
  
  <pre><code>$objGroup = [ADSI]("WinNT://$Env:COMPUTERNAME/Administrators")
  $objGroupMembers = $objGroup.psbase.Invoke("Members") | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',$null, $_, $null)}
  $objRemoveGroup = [ADSI]("WinNT://Contoso/ABC-MyAdmins")
  $objGroup.PSBase.Invoke("Remove",$objRemoveGroup.PSBase.Path)
  </code></pre>
  
  <p>But the groups I need to remove will be removing could be named XYZ-MyAdmins or ABC-XYZ-MyAdmins. Basically I just want to remove any member of the Local Administrators group that is like *-MyAdmins.</p>
  
  <p>So if I do something like this, it doesn't work:</p>
  
  <pre><code>$objGroup = [ADSI]("WinNT://$Env:COMPUTERNAME/Administrators")
  $objGroupMembers = $objGroup.psbase.Invoke("Members") | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',$null, $_, $null)}
  $ObjRemove = ForEach($Member in ($objGroupMembers | Where-Object {$Member -like '*-MyAdmins'}))
  {
  $objRemoveGroup = [ADSI]("WinNT://Contoso/$($ObjRemove)")
  $objGroup.PSBase.Invoke("Remove",$objRemoveGroup.PSBase.Path)
  }
  </code></pre>
  
  <p>What am I doing wrong here?</p>