Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Canot remove users from local server group

Status
Not open for further replies.

JPaisley

MIS
Dec 15, 2004
4
US
I am trying to remove all users from a local group across 150+ server in our environment.

When I run the script I get an error stating 'The specified account is not a member of the local group.'

I have noticed that the users in the group display with a sid in parenthesis after the user name. I asume this is in reference to the sidhistory object of each user.

Any ideas how to get these users removed from the groups?


'***************
Dim objSrvr
Dim objGroup
Dim strPath,strUserPath

' Construct the binding string.
strPath = "WinNT://Servername"

' Bind to object.
Set objSrvr = GetObject(strPath)

' Enumerate groups and members.
objSrvr.Filter = Array("group")

For Each objGroup in objSrvr
If UCase(objGroup.Name) = "HRIS" Then
For Each objMember in objGroup.Members
strUserPath=objMember.adspath
objGroup.remove strUserPath
Next
End If
Next
'***************


Thanks,
Joe P
 
How about this.

Code:
' Delete Users from a Local Group

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
strGroup = "hris"
WScript.Echo "Computer: " & strComputer
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
WScript.Echo "" & strGroup &" group members:"
For Each objMember In objGroup.Members
  WScript.Echo "    " & objMember.Name
  WScript.Echo ("WinNT://" & strComputer & "/" & objMember.Name & ",user")
Next

For Each objMember In objGroup.Members
    Set objUser = GetObject("WinNT://" & strComputer & "/" & objMember.Name & ",user")
  objGroup.Remove(objUser.ADsPath)
Next

Hope this helps.

Thanks

John Fuhrman
Titan Global Services
 
No luck...

They accounts are not local they are domain accounts. So I substitued my domain name where you had strComputer on the below line.

'Set objUser = GetObject("WinNT://" & strComputer & "/" & objMember.Name & ",user")'

But I receive the same error about the user not being a member of the group.

 
Your OP says

I am trying to remove all users from a [highlight]local group[/highlight] across 150+ server in our environment.

So I wrote a script that could be run on a server to remove all user accounts from a LOCAL group.

What are you trying to do. Please elaborate.



Thanks

John Fuhrman
Titan Global Services
 
That is exatly what I am trying to do.

When you view the group members through the GUI they display as

domainname/JPAISLEY (S-1-5-XXXXX)

When the script tries to remove the user I receive the 'specified user is not a member of the local group' error.
 
OK, I will try to do some testing on one of my QA servers in our domain. It will be tomarrow before I can finish though.

Thanks for the explanation, that did help.



Thanks

John Fuhrman
Titan Global Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top