Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-14
2
Medium Priority
?
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
fhmc earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

610 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