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 gkittelson 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

Status
Not open for further replies.

fong21051

Technical User
Jun 1, 2012
38
GB
Hello,

I'm trying to write a vbscript which deletes all users from a specific Active directory OU, and all his data.

Here's the info:

Profiledata location: \\server\profile$\accountname
Userdata location: \\server\userdata$\accountname
domainname: rcm.ac.uk


All the users to be deleted are in one specific sub OU (the location of OU: rcm.ac.uk > people > staff leavers > definite staff leavers).

I want the script to delete all the users in this "definite staff leavers" OU,
and also to delete each of the corresponding user's profile and userdata from the location above.
The user's profile and userdata is given the same name as the "user logon name" field in AD (in the "account" tab in the properties of the user in AD).
Is it possible to create a "lookup" so that it deletes the user profile and userdata first before deleting the account from AD?

I'm just an admin and not a programmer so I'm unsure how to do this. Please can someone help

Many thanks
 
Hi Everyone,
I have researched this forum and amended the code according to someone else's issue to:


Option Explicit
Dim subou
Dim mainou
Dim Inputname
Dim loginname
Inputname = InputBox("Enter the username")
loginname = InputBox("Enter the loginname")
Set objUser = GetObject("WinNT://rcm/" & NTUsername & ",user")
objUser.delete
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\rcm-file\staffprof$\" & loginname)
objFSO.DeleteFolder("\\rcm-file\accounts$\Users" & loginname)

----------------------------------------

but now I am receiving error:

line:8
char:1
error: variable is undefined: 'NTUsername'
code: 800A01F4
source: Microsoft VBScript runtime error


I don't know what this means. Please can anyone help.
Thanks.
 
This?
Code:
Set objUser = GetObject("WinNT://rcm/" & [COLOR=blue]Inputname[/color] & ",user")
or
Code:
Set objUser = GetObject("WinNT://rcm/" & [COLOR=blue]loginname[/color] & ",user")
 
Hi Guitarzan,
Thanks for getting back to me on this.
I have now amended the code to the following:
---------------------------------------------
Option Explicit
Dim subou
Dim mainou
Dim Inputname
Dim loginname
Inputname = InputBox("Enter the username")
loginname = InputBox("Enter the loginname")
Set objUser = GetObject("WinNT://rcm/" & loginname & ",user")
objUser.delete
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("\\rcm-file\staffprof$\" & loginname)
objFSO.DeleteFolder("\\rcm-file\accounts$\Users" & loginname)

-------------------------------------------------------------

But now I am receiving error message:

Line: 8
Char: 1
Error: The network path was not found
code 80070035
source (null)


-------------------------------------------
The user login name is: script.test
but the profile and data path does exist. They are in the following location:

\\rcm-file\staffprof$\script.test
\\rcm-file\accounts$\Users\script.test

Can you possibly help amend my code or improve it? Any help is much appreciated!

Thanks,
ICT/Fong
 
Assuming line 8 is [highlight]Set objUser = GetObject("WinNT://rcm/" & loginname & ",user")[/highlight], it is indicating that the computer named "rcm" cannot be found
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top