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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete active directory accounts, profiles and userdata 2

Status
Not open for further replies.

ensing

Technical User
Apr 2, 2004
10
0
0
NL
Hello,

I'm trying to write a vbscript which deletes a user from the Active directory and all his data.

Here's the info:

Profiledata location: \\server\profile$\accountname
TSprofiledata location: \\server\tsprofile$\accountnameUserdata location: \\server\userdata$\accountname
domainname: newyork.america.com


The users are most often in several subOU's.
I wan't the script to prompt for the accountlogonname. Then I wan't to fill in the loginname and the the script must delete the AD useraccount and the directory's above.

I already tried the thing below but it doesn't work. I have to fill in the userdisplay name as in AD. I also have to fill in AD ou's which I most of the time don't know. I have to fill in to many things. Also it only deletes the first directory and not the other two.
I'm just an admin and not a programmer so please help me with some dummie vbscript.

Thanks for your help.


On Error Resume Next
Dim subou
Dim mainou
Dim Inputname
Dim loginname
subou = InputBox("enter the subou ")
mainou = InputBox("enter the mainou")
Inputname = InputBox("Enter the username")
loginname = InputBox("Enter the loginname")
set objOU = GetObject("LDAP://ou="& subou & ",ou=" & mainou &",dc=newyork,dc=america,dc=com")
objOU.Delete "user", "cn= " & loginname
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\grnnt025\profiles$\" & loginname)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\grnnt025\TSprofiles$\" & loginname)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\grnnt025\userdata$\" & loginname)
 
not sure i like what you intimating with 'dummie' vbscript!!

1. Turn off 'On error resume Next'

2. swap it with Option Explicit, it will be much more useful

you are erroring when you try the second
Set objFSO = CreateObject("Scripting.FileSystemObject")
you have already created a reference to a filesystemobject, why not reuse that one???? so,

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\grnnt025\profiles$\" & loginname)
objFSO.DeleteFolder("\\grnnt025\TSprofiles$\" & loginname)
objFSO.DeleteFolder("\\grnnt025\userdata$\" & loginname)


AD still supports the WinNT provider, use it, it might help you out,
so instead of

set objOU = GetObject("LDAP://ou="& subou & ",ou=" & mainou &",dc=newyork,dc=america,dc=com")
objOU.Delete "user", "cn= " & loginname

try
Set objUser = GetObject("WinNT://newyork/" & NTUsername & ",user")
objUser.delete

that way you dont need to know all the other rubbish, just the NT user account name
 
Got the following error:
Line: 4
Char: 1
Error: Object doesn't support this property or method: 'objUser.Delete'
Code: 800A01B6
Source: Microsoft VBScript runtime error

I realy don't know
 
Hello ensing,

Do this rather.
Code:
objUser.Parent.delete "user",objUser.name
regards - tsuji
 
Now I receive
Error: Object required: 'objUser.Parent'

Sorry I'm really not a programmer.
 
ensing,

In any case, delete the objUser from its container.
Code:
Set objContainer = GetObject("WinNT://newyork")
Set objUser = GetObject("WinNT://newyork/" & NTUsername & ",user")
objContainer.delete "user",objUser.name
If anything else happens, it can be that the user object is not there at all. (Use on error resume next to trap it.)

-tsuji

objContainer.Delete "user",
 
Hi.. I have a post for some thing simular but its on a standalone server so not active directory, if you can help please check out the post...Please

ITOpMan
 
itopman,
seeing as this post uses the WinNT provider it shouldnt make any difference if it is a standalone server, you should be able to use the same code, whats your thread id?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top