Page 1 of 2 12>
Topic Options
#40210 - 2003-05-15 02:36 PM Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Hi Everyone

I am trying to delete all the groups from the users group membership list.

I was hoping there would be a nice easy command, but have searched through ADSI and Microsoft site and found nothing.

Don't care how I do it, kix or another command.

One way I did think of was to list the group membership of that user then delete the groups that are listed.

This would work but I am not able to write the code, above my technical ability :-(.

Thanks

Top
#40211 - 2003-05-15 02:40 PM Re: Delete all Groups from users group membership list
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
AD or NT domain?
_________________________
!

download KiXnet

Top
#40212 - 2003-05-15 02:40 PM Re: Delete all Groups from users group membership list
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Isn't this something that LDIFE or CSVDE handles? Kinda like the old Reskit tool ADDUSERS? Or, are you asking to remove all groups from say a specific user, but keep the Account on the domain?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#40213 - 2003-05-15 02:46 PM Re: Delete all Groups from users group membership list
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Actually, I think the task would not be above your technical skill level. [Smile]

Try it and see.

Use EnumGroup() and EnumLocalGroup() (if req.) to enumerate the groups to which the user is a member. Examples are in the manual and on the board.

For each group name $grp = GetObject(winnt://domain/groupname). Remove the user $grp.remove(Winnt://domain/user)

[ 15. May 2003, 14:46: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#40214 - 2003-05-15 02:46 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Sorry I am running Windows 2000 Server, with all 2k workstations. AD

say a user is a member of 5 groups, i want to clear the list of groups for that user only.

So I want to keep the account on the domain just get rid of the group memberships of that user

Thanks

Top
#40215 - 2003-05-15 02:48 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thanks Howard

Just need that little nudge, makes sense I will look into it. [Wink]

Thanks

Top
#40216 - 2003-05-15 02:57 PM Re: Delete all Groups from users group membership list
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Also, you can do a simple ADSI script...

code:
Break On CLS

$sUser = "Test"

$objUser=GetObject("WinNT://"+@DOMAIN+"/"$sUser)
"Groups for " $objUser.Name ?
For Each $objGroup in $objUser.Groups
$objGroup.Name " - " $objGroup.Description ?
$objGroup.Remove ($objUser.AdsPath)
Next


Top
#40217 - 2003-05-15 02:59 PM Re: Delete all Groups from users group membership list
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
BTW, the above sample script removes the user from all groups except Domain Users. [Big Grin] [Wink]
Top
#40218 - 2003-05-15 03:01 PM Re: Delete all Groups from users group membership list
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what is a user account if it is not a domain user account?
think that is ok to be left there [Wink]
_________________________
!

download KiXnet

Top
#40219 - 2003-05-15 03:02 PM Re: Delete all Groups from users group membership list
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Chris, that looks awful familiar. Did you or I post that previously?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#40220 - 2003-05-15 03:05 PM Re: Delete all Groups from users group membership list
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Hmm. Well, its just a one line add to enuming through a user's (or with slight mod, computer's) group membership.

Pretty basic stuff really. I can't think of too many ways (that make sense) to do it differently. [Big Grin]

Top
#40221 - 2003-05-15 03:23 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
One problem ENUMGROUP works with the current user, I want to delete the list of groups for $x user.

Just when you thought it was nice and easy.
[Big Grin]
Rich

Top
#40222 - 2003-05-15 03:24 PM Re: Delete all Groups from users group membership list
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
richard, so you saying that the code that was provided to you does not work?
_________________________
!

download KiXnet

Top
#40223 - 2003-05-15 03:26 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Doh sorry guys, so many replys I didn't see your example script Chris.

Thanks

Top
#40224 - 2003-05-15 03:30 PM Re: Delete all Groups from users group membership list
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Domain users have be a member of at least one group, the Primary Group (by default Domain Users) in an NT domain. Is this still the case under AD? I would assume so.

[ 15. May 2003, 15:30: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#40225 - 2003-05-15 03:32 PM Re: Delete all Groups from users group membership list
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Richard, see what you happens when you ask for help. [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#40226 - 2003-05-15 04:04 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Hi Guys

I have converted it to use LDAP connection instaed of WinNT.

So simple when you get some help :-)

Thanks

code:
  
$objUser = GetObject("LDAP://" +$TranslateUserName[0])
For Each $objGroup in $objUser.Groups
$objGroup.Remove ($objUser.AdsPath)
Next



[ 15. May 2003, 16:08: Message edited by: Richard Farthing ]

Top
#40227 - 2003-05-15 04:09 PM Re: Delete all Groups from users group membership list
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Cool. BTW, you can still use the WinNT provider in with an AD network (we just converted to AD last weeked). My example will work on either an NT4 or AD network. [Wink]
Top
#40228 - 2003-05-15 04:16 PM Re: Delete all Groups from users group membership list
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Yep worked fine using WinNT, but my script uses all LDAP connection and wanted to keep it the same.

Thanks again Chris

Top
#40229 - 2003-05-15 05:52 PM Re: Delete all Groups from users group membership list
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
The only caveat I could think of with this...

If you remove all groups from a user, that also includes "Domain Users" you may run into conflicts with your application set.

If you remove them from the group, then the point is moot.

BTW, did you know that you can achieve alot of this with the "query" functionality of AD Users and computers in XP? You can save the queries and export the data too.

Cheers!

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.037 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org