Solved

Batch Script help

Posted on 2015-01-23
3
128 Views
Last Modified: 2015-02-18
I have the following batch script which grabs computer names out of "ad.txt" and then uses psexec to remote to the computer, grab the UUID, and then add the entry into AD so I can make existing computers Managed in AD.  

My issue is that the script is not working.  What am I missing?
_________________________________
for /F "tokens=*" %%F in (ad.txt) do call :wdsadd %%F
exit /b

:wdsadd
for /f %%I IN (
'psexec  \\^%1 cmd /c "echo csproduct get UUID|wmic.exe" ^| ^
findstr /r ........-....-....-....-............ '
) do wdsutil /set-device /device:%1 /id:%%~I
exit /b
0
Comment
Question by:mrfite
[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
3 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40566468
On quick glance, your code looks find.

Do you have specific errors? Can you share those?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40566827
Will just say aswell did you know you can use the mac address against the computer in ad too to the same purpose , presumably for building etc?

On phone at mo. but have various scripts we used for some if that before, mainly vbscripts if any end up wanted.

Steve
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40567154
My guess would be that ad.txt is a Unicode file, and "for /f" chokes on Unicode. Open it in Notepad, go to File > Save As, and check what it says under "Encoding". Change the encoding to ANSI, or use "for /f %%a in ('type ad.txt')".
Then there's no real need for psexec; wmic has the /node argument for remote WMI.
This works for me; it's in test mode and will only display the wdsutil commands it would normally run; remove the uppercase ECHO in line 6 to run it for real:
@echo off
setlocal
set ComputerFile=AD.txt
for /f "tokens=*" %%c in ('type "%ComputerFile%"') do (
	for /f %%i in ('wmic.exe /node:%%c csproduct get UUID ^| findstr.exe /r "........-....-....-....-............"') do (
		ECHO wdsutil.exe /set-device /device:%%c /id:%%i
	)
)

Open in new window

0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…

739 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