title: Error while removing Users/groups from Local administrators through Powershell
body: <p>I need to remove few domain users and groups from number of servers from their local administrators group , as part of a project. Since doing the same thing for many servers will consume lot of time, I was thinking to do the same through powershell.
  Below is the code I'm using:
  First, I'm trying to do it locally on one server. Once this is successfull I'll use a forloop to run it for all servers at once.</p>
  
  <pre><code>$RemoteComputer = "US05APP9008.jnj.com"
  $Computer = [ADSI]("WinNT://$RemoteComputer,computer")
  $Group = $Computer.PSBase.Children.Find("Administrators")
  $account="domain\groupname"
  $Group.Remove("WinNT://$account")   
  </code></pre>
  
  <p><strong>Error</strong>
  <em>Exception calling "Remove" with "1" argument(s): "A member could not be added t
  o or removed from the local group because the member does not exist.
  "
  At C:\Users\admin_broy5\Desktop\remtest.ps1:6 char:14
  + $Group.Remove &lt;&lt;&lt;&lt; ("WinNT://NA\admin_broy5")
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI</em></p>
  
  <p>I tried the same through another code as well found from some other forum in stackoverflow but it also gave the same error:</p>
  
  <pre><code>$CompStat = Get-WmiObject win32_computersystem;
  $Localhst = $CompStat.Name;
  $Computer = [ADSI]('WinNT://'+$localhst+',computer');
  $accName = [ADSI]('WinNT://NA\admin_broy5,user');
  $group = [ADSI]('WinNT://'+$Localhst+'/Administrators,group');
  $group.remove($accName.path);
  </code></pre>
  
  <p><strong>Error:</strong>
  <em>Exception calling "remove" with "1" argument(s): "An invalid directory
  pathname was passed
  "
  At C:\Users\admin_broy5\Desktop\rem.ps1:6 char:1
  + $group.remove($accName.path);
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~</em></p>
  
  <p>Kindly let me know how can I achieve my objective?
  Thanks in advance!!!</p>