PC moving OUs batch script

Hello Buds,

I was wondering if anybody can perhaps give me a hand with this script(.cmd) that I need

From a pclis.txt move these computer to a custom OU. Please notice some OUs have spaces in between the names, so I noticed the following eg.

in my own
pclist.txt
"CN=Computerkitchen,OU=Acme,OU=USA california,DC=apple,DC=com"

Open in new window

 

   
   
script.bat:
"For /F  %a in (pclist.txt) do dsmove %a -newparent "ou=Marketing,dc=microsoft,dc=com""

Open in new window


   it will give me an ERR and would pull only the name from my own pclist, like this
@prompt    

dsmove "CN=Computerkitchen,OU=Acme,OU=USA" -newparent "ou=Marketing,dc=microsoft,dc=-com"

Open in new window


    Error pc not found...(I know it's different error I didn't get a chance to write the exact error code)

Any thoughts? or does anybody have a different approach?
 

in any of the events, thanks for looking out
LVL 3
ivan rosaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
The "script" you posted will only work in a command prompt, not in a batch script; in a batch script, loop variables like %%a need to have double percent signs.
That said, the default delimiters for "for /f" are space and tab, so if you want to read lines that include either one of these characters, you need to change the delim to none, so that the line won't be broken into tokens:
Command prompt:
For /F "delims=" %a in (pclist.txt) do dsmove %a -newparent "ou=Marketing,dc=microsoft,dc=com"

Open in new window

Batch:
For /F "delims=" %%a in (pclist.txt) do dsmove %%a -newparent "ou=Marketing,dc=microsoft,dc=com"

Open in new window

Note that sometimes text files are saved in Unicode, which "for /f" can't handle directly. A "type ..." helps to avoid that:
For /F "delims=" %%a in ('type "pclist.txt"') do dsmove %%a -newparent "ou=Marketing,dc=microsoft,dc=com"

Open in new window

Edit: added Unicode hint.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ivan rosaAuthor Commented:
oBdA,
Sweet!, I can't wait to test it out ... and thanks for schooling me, I  really appreciate it, I took a course for QBASIC and Turbo Basic, back in 1998 but things have changed ever since...

i wish ''notepad++' had the "run" functionality, like  Turbobasic did...Ahhh! good old days!

I'm having trouble with the concepts of tokens vs delims and strings..., once I get that concept of all straight, watch-out you might just get a challenger ;) ..... you know any good books you would recommend?
oBdACommented:
There are lots of good batch (and other script) examples at http://www.robvanderwoude.com/
And you can start batch scripts easily directly from Notepad++: hit F5 (or "Run > Run..." from the menu bar),, enter (exactly like this) C:\Windows\system32\cmd.exe /k "$(FULL_CURRENT_PATH)" (the /k keeps the window open once the script is done). You can then optionally click "Save" and assign a hotkey.
ivan rosaAuthor Commented:
This guy is a legend!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.