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
Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article runs through the process of deploying a single EXE application selectively to a group of user.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
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…
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 …

837 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