Page 1 of 1 1
Topic Options
#25419 - 2002-07-19 05:42 AM Deleting Users in W2000
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
I would like a script that deletes a group of W2000 users from AD along with their homedir. When students leave my school I disable their accounts and put them in a group called "Delete these later". Group is growing in number - 200,say, - so manual option is not efficient. Can anyone help please? [can't find anything in the archives]
Top
#25420 - 2002-07-19 07:40 AM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Hello briannz556,

This isn't McDonalds or Burger King (you can't just have it your way!) [Big Grin]

Seriously though... There are only a few members that appear to be running AD and know how to write a script that you're looking for.

I won't guarantee that I will write one for you, but if I get the time, I'll look at writing one.

Do you know your DSE or how to modify code to use it, if I do write one?

Top
#25421 - 2002-07-19 02:57 PM Re: Deleting Users in W2000
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Do you want fries with that? [Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25422 - 2002-07-19 03:06 PM Re: Deleting Users in W2000
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You best bet is to read the COM forum, download the ADSI documentation from Microsoft, and write a script using ADSI. It is definitely possible to go where you want to go...

Anyway, most of the code fragments that you will require are already posted on this BBS. Use the BBS search to find those fragments and start building you script. Once you got it somewhat working, we'd be more than helpful in assisting you with specific questions and/or debugging problems.
_________________________
There are two types of vessels, submarines and targets.

Top
#25423 - 2002-07-20 07:43 AM Re: Deleting Users in W2000
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Thanks for all that. Yes, wording did leave something to be desired. Really keen to do the donkey work just need titbits to work around from which to formulate a solution.
Top
#25424 - 2002-07-20 11:24 AM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Brian,

Is your AD and users setup something like this?

code:
:MyCompany
:--Computers
:--Delete these later
:----jeff
:----brian
:----greg
:--Groups
:--Policies
:--Servers
:--Users
:----bill
:----dave
:----steve
:--TestGroup

And if so,
1. Does their Home Folders match their logon name?
2. Are they all on the same Server?
3. Are the user folders all under the same PARENT FOLDER. ie. D:\USERS\...

You can use this code to list the users in the group. Then remove the semi colon to create a log of those users.
Then you could also modify it to delete user folders based on this info.

code:
; ListUsersInOU.kix
break on
CLS
;REDIRECTOUTPUT ("C:\TEMP\Delete these later.TXT", overwrite)
$Users = GetObject("LDAP://ou=Users,ou=MyBusinessUnit,dc=MyRegion,dc=MyCompany,dc=com")
for each $member in $Users
? $member.SamAccountName
next
;REDIRECTOUTPUT ("")

If you need further assistance please let us know. Once you have the full working code completed, please post an update with the code so that others may also learn from your experience.

Top
#25425 - 2002-07-21 05:09 AM Re: Deleting Users in W2000
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Thanks NTDOC. In answer to your questions: Yes, Yes and Yes.

Will trial your coding this week when I get the chance and report back.

Top
#25426 - 2002-07-23 08:19 AM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Haven't forgotten you briannz556

Between work and home remodeling job... going to bed at 02:00 each night.. Does not leave a lot of time for "extra" unscheduled work. [Big Grin]

Is the Server the users are on, also on the Domain Controller? or a stand alone server ( I hope - for security reasons ).

Top
#25427 - 2002-07-23 10:52 PM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Ok Brian... I'm back. Fries are Ready [Big Grin]

Here is some code that should do the trick with hopefully little modification. Change your RootDSE and your User Server and it should do the trick. Not sure what or how it affects email in AD. I did not do that kind of testing and I don't have the account authority to test Email deletion via this method.

***** Note: The MESSAGEBOX is all one line, only broken here for display.
*****

WARNING!! This is VERY DANGEROUS code... You could wipe out ALL the USERS AND DATA by using the wrong pathing. There would be no error checking and no way to UNDO the deletions. - USE/MODIFY AT YOUR OWN RISK!

code:
; DeleteUserAccounts.kix
; By NTDOC 07-23-2002

Break On
$nul = MESSAGEBOX("This script will DELETE ALL accounts in the specified OU and remove the Home Folder and ALL data... _
WARNING - WARNING This is an irreversible action. Click CANCEL to quit now, otherwise the removal of all accounts _
and data will continue...", "User Account Deletion", 273)
If $nul = 1
$Users = GetObject("LDAP://ou=Testing,ou=MyRegion,dc=MyDomain,dc=MyCompany,dc=com")
; You need to modify the $Users LDAP for your own AD path.
$Users.filter = "a","User"
For Each $member in $Users
$x = $member.SamAccountName
? "Removing account and home folder for "+$x
Shell '%COMSPEC% /C RD /S /Q "\\MyServer\USERS\$x"'
$Users.Delete ("User", $member.name)
? ''+@ERROR+' - '+@SERROR
Next
Endif

Please post an update when you can to let us know how it works out.

[ 23 July 2002, 23:23: Message edited by: NTDOC ]

Top
#25428 - 2002-07-31 07:32 AM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
knock knock come on back Brian.

Did this work for you? What's up?
You didn't use the wrong path and delete all your real users did you? Hope you did not get fired [Eek!]

Please post an update when you get a chance.

[ 31 July 2002, 07:33: Message edited by: NTDOC ]

Top
#25429 - 2002-08-04 10:14 PM Re: Deleting Users in W2000
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Sorry Guys, I get but 2hrs a week to do my ancillary programing at school so I have to fit in this task when I can. Just finishing off main log-in script file. Hope to get back to this later in August. haven't forgotten I assure you.
Top
#25430 - 2002-09-19 09:41 AM Re: Deleting Users in W2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Brian.... any update?
Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1172 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.108 seconds in which 0.071 seconds were spent on a total of 12 queries. Zlib compression enabled.

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