Solved

Batch Script help

Posted on 2015-01-23
3
126 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 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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