From: joe [mailto:support@joeware.net]
Sent: xxx
To: xxx
Subject: RE: Support Reuest
Hi xxx,
You won’t be able to do this with just usernames in a file with just adfind/admod, you would need a script to add the additional logic to look up the usernames and convert to DNs.
However, if you have a list of user DNs in a file or you can execute a single query to locate the users you can do this with no scripting.
So say you have a list of DNs in the file userlist.txt, you could do something like
adfind homedirectory -adcsv < userlist.txt | admod homedirectory::{{.:r:oldservername:newservername}} -upto maxcount
This takes the DNs from the text file, looks up the current homedirectory value, passes that through the pipe to AdMod which then takes the current value and replaces the oldservername with the newservername and inserts it back into the user object. You specify the -upto switch to specify the maximum number of objects you want to update. By default, admod will bail out and make no changes if more than 10 objects are passed to it, this is to protect people from accidently modifying large numbers of objects by accident. You can modify the safety value with –safety x, this will tell how many items AdMod should be able to modify without bailing out and making no changes. You can use the –upto x switch which will tell it only do the first x updates. Or if you are positive you are good on the specific objects, you can specify –unsafe which tells admod to update anything passed to it.
Example:
Here is the user list
G:\Temp>type userlist.txt
"CN=auser1,OU=XXXTest,DC=test,DC=loc"
"CN=auser2,OU=XXXTest,DC=test,DC=loc"
"CN=auser3,OU=XXXTest,DC=test,DC=loc"
"CN=auser4,OU=XXXTest,DC=test,DC=loc"
Here is the current homedirectory values for that group of users
G:\Temp>adfind homedirectory -adcsv < userlist.txt
~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~
"dn","homedirectory"
"CN=auser1,OU=XXXTest,DC=test,DC=loc","\\server1\auser1"
"CN=auser2,OU=XXXTest,DC=test,DC=loc","\\server1\auser2"
"CN=auser3,OU=XXXTest,DC=test,DC=loc","\\server1\auser3"
"CN=auser4,OU=XXXTest,DC=test,DC=loc","\\server1\auser4"
Here is the change
G:\Temp>adfind homedirectory -adcsv < userlist.txt | admod homedirectory::{{.:r:server1:server2}} -unsafe
AdMod V01.12.00cpp Joe Richards (joe@joeware.net) February 2010
DN Count: 4
Using server: TEST-DC1.test.loc:389
Directory: Windows Server 2003
Modifying specified objects…
DN: CN=auser1,OU=XXXTest,DC=test,DC=loc…
DN: CN=auser2,OU=XXXTest,DC=test,DC=loc…
DN: CN=auser3,OU=XXXTest,DC=test,DC=loc…
DN: CN=auser4,OU=XXXTest,DC=test,DC=loc…
The command completed successfully
Here are the new values
G:\Temp>adfind homedirectory -adcsv < userlist.txt
~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~~~~ADCSV~~~
"dn","homedirectory"
"CN=auser1,OU=XXXTest,DC=test,DC=loc","\\server2\auser1"
"CN=auser2,OU=XXXTest,DC=test,DC=loc","\\server2\auser2"
"CN=auser3,OU=XXXTest,DC=test,DC=loc","\\server2\auser3"
"CN=auser4,OU=XXXTest,DC=test,DC=loc","\\server2\auser4"
Hope this helps.
joe
—
O’Reilly Active Directory Fourth Edition – http://www.joeware.net/win/ad4e.htm
From: xxx
Sent: xxx
To: support@joeware.net
Subject: Support Reuest
Dear Joe!
I’d like to congratulate for your site.
There is a big problem, what you could solve for me.
I want to change my fileserver and i want to move user’s fomefolders.
The users are in a USER container(not an OU) in AD.
And they are 260.
How can I change from \\abc\home\user to \\xyz\home\user with your tools?
How can i change it from a file which in contains usernames?
Wich is the best solution export only username from a AD container? And how to use it with admod tools?
Thank You:
xxx
I’m currently in the middle of moving my users from individual file servers to a nice big san.
Since I’m migrating over 1000+ users to a central file store, I decided to organize my home folders like so:
joe = \\domain\public\home\staff\j\joe
davis = \\domain\public\home\staff\d\davis
… and so on …
This prevents everyone from going into one big folder which takes forever for Windows Explorer to load if you’re navigating to the root folder.
Note that I have DFS setup so the UNC path includes the domain name.
Here is my _updateHomeDirectories.cmd script:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM Get rid of the ugly UNC error DOS
REM likes to throw at you.
CLS
SET _dir=%~dp0
SET _tools=%_dir%\Tools
SET _dc=domaincontroller1
REM If I pass the home folder to the script
REM …don’t ask me for it again
IF [%1] == [] (
ECHO Please enter the UNC path to the root of the current user directory.
SET /P _userdir=For example [\\oldserver\d$\users]: ||GOTO:EOF
) ELSE (
SET _userdir=%1
)
FOR /F %%a IN (‘DIR /B %_userdir%’) DO (
SET _user=%%a
SET _firstinitial=!_user:~0,1!
%_tools%\dsquery.exe user -samid !_user! | %_tools%\dsmod.exe user -hmdir \\domain\public\home\staff\!_firstinitial!\!_user! -s %_dc%
)
PAUSE
I know this doesn’t use any of your tools, but believe me, I use them quite often!!