Solved

Batch Script help

Posted on 2015-01-23
3
119 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
3 Comments
 
LVL 23

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 83

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now