Solved

Need script to clear home drive AD attributes from a list of users

Posted on 2008-06-14
2
468 Views
Last Modified: 2010-04-21
I have a list of user accounts (username only, one user per line) in a text file, and I need a way to remove the home drive attributes from these users active directory accounts. I'm looking for a vbscript that will read this text file, and for each user search a given OU (and all OUs underneath that OU) and if it finds the user, it removes the home drive attributes from their accounts.

If possible, I'd also like it to output to a file containg each account that it processed and it's location in AD, as well as its success or failure.

Any help would be appreciated. Thanks!

0
Comment
Question by:TWCMIL
2 Comments
 
LVL 7

Accepted Solution

by:
fhmc earned 500 total points
ID: 21786918
I just scrambled this idea together and only tested it briefly....  AND it's not a VB answer...  that said

from a cmd prompt (this can be customized to run via a logon script, another bat file, etc.)  e.g. this approach wouldn't be too hard to customize for your environment:

create a batch file... call it homedirmod.bat for now
:: log username
echo %1 >> log.txt
:: set user's home dir to nul
net user /domain %1 /homedir:
::  log user's homedir path...  no data should be present to the right of the Home Directory reference
net user /domain %1 |find "Home" >> log.txt
::  find and log user's OU container
dsquery user -samid %1  >> log.txt

:end


now, call that batch file in the following manner:

for /f %1 in (yourtextfilenamethatcontainsuseraccounts) do call homedirmod.bat %1



your logfile should resemble something like:

username
Home Directory
OU
username
Home Directory
OU
etc.
0
 
LVL 1

Author Closing Comment

by:TWCMIL
ID: 31467251
This works perfectly for me. No problem that it wasn't vbscript, I had assumed that it couldn't be done via batch file and I was wrong. One small correction I had to make was in the command to call the batch file:

for /f %i in (yourtextfilenamethatcontainsuseraccounts) do call homedirmod.bat %i

Had to change the %1 to %i, then it worked properly. Thanks again for your help.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question