Recently, we have to do some cleanup on our company’s Active Directory. So we written some dsquery and dsmove scripts to do this and adding it to our daily, weekly, and monthly scheduled tasks. All of our dsquery, dsmove, dsadd, dsget, dsrm are ran in batch files. In order to get the batch files to run piped dsquery to dsmove, you will need to use the “FOR” loop method.
For /F “delims=” %%a in (‘dsquery computer “CN=computers,DC=drf,DC=corp”‘) DO (dsmove -newparent “OU=Workstations,DC=drf,DC=corp” %%a)
Another things to keep an eye on is that when saving to a batch file, you will need to have the %% variable instead of just %. Otherwise, the batch file will fail.
e.g. correct way is “%%a”
wrong way is “%a”
But, to run it stand alone you will need to do the opposite.
e.g. correct way is “%a”
wrong way is “%%a”