Solved

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

Posted on 2008-06-14
2
460 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

Join & Write a Comment

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now