[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Batch Script help

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
mrfite
Asked:
mrfite
1 Solution
 
NVITCommented:
On quick glance, your code looks find.

Do you have specific errors? Can you share those?
0
 
Steve KnightIT ConsultancyCommented:
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
 
oBdACommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now