[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Batch Script help

Posted on 2015-01-23
3
Medium Priority
?
133 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 25

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 85

Accepted Solution

by:
oBdA earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 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