ben604 Posted May 30, 2012 Posted May 30, 2012 I'm trying to import our machines from Fog into our new AD using this script I found on the interwebs: for /f "tokens=1,2 delims= " %a in (fogreport.csv) do wdsutil /Set-Device /Device:%a /ID:%b It's reading the CSV but combining both the %a and %b columns into the /Device: field, giving an error that the input for /ID: is incorrect... Any ideas what I'm doing wrong? I'm using a CSV on Windows 7 Thanks in advance, Ben
X-13 Posted May 30, 2012 Posted May 30, 2012 I would check what is being picked up as %b. It may as simple as it's picking up the wrong thing. Also, if it's a CSV... why isn't the delimiter a comma? 1
ben604 Posted May 30, 2012 Author Posted May 30, 2012 I would check what is being picked up as %b. It may as simple as it's picking up the wrong thing. Also, if it's a CSV... why isn't the delimiter a comma? The output is wdsutil /Set-Device /Device:moodle,00:11:22:33:44:55 /ID: (blank) Where do I define the delimiter, sorry not my strong suite, command line stuff...!
Steve21 Posted May 30, 2012 Posted May 30, 2012 The output is wdsutil /Set-Device /Device:moodle,00:11:22:33:44:55 /ID: (blank) Where do I define the delimiter, sorry not my strong suite, command line stuff...! Not sure if it'll work as I didn't test it, but seesm you have same problem someone did yesterday for /F "tokens=1,2 delims=," %%1 in (ahosts.txt) do echo %%1 %%2 Note double %% Steve 1
X-13 Posted May 30, 2012 Posted May 30, 2012 (edited) The output is wdsutil /Set-Device /Device:moodle,00:11:22:33:44:55 /ID: (blank) Where do I define the delimiter, sorry not my strong suite, command line stuff...! delims= I think it should be delims=, [with 100% extra comma, free!] If /ID: is blank, I would check the CSV. From what is being used in /Device: it looks like it's using both. If I'm understanding it correctly, it should be /ID:00:11:22:33:44:55. Not sure if it'll work as I didn't test it, but seesm you have same problem someone did yesterday for /F "tokens=1,2 delims=," %%1 in (ahosts.txt) do echo %%1 %%2 Note double %% Steve Double in a batch file, single in command line. It entirely depends on how it's being used. Edited May 30, 2012 by X-13 1
plexer Posted May 30, 2012 Posted May 30, 2012 for /f "tokens=1,2 delims=, " %%a in (fogreport.csv) do wdsutil /Set-Device /Device:%%a /ID:%%b Should do it? Ben 1
plexer Posted May 30, 2012 Posted May 30, 2012 When using for in a batch files you need to use a double % if runnign it direct from a command prompt you use a single % Ben 1
ben604 Posted May 30, 2012 Author Posted May 30, 2012 Thanks guys, tried all those variations with no results... for /f "tokens=1,2 delims=, " %a in (fogreport.csv) do wdsutil /Set-Device /Device:%a /ID:%b gives wdsutil /Set-Device /Device:moodle /ID:%b
Steve21 Posted May 30, 2012 Posted May 30, 2012 Thanks guys, tried all those variations with no results... for /f "tokens=1,2 delims=, " %a in (fogreport.csv) do wdsutil /Set-Device /Device:%a /ID:%b gives wdsutil /Set-Device /Device:moodle /ID:%b Because you ignored all of us Double %% ! Steve
X-13 Posted May 30, 2012 Posted May 30, 2012 Because you ignored all of us Double %% ! Steve %a is setting fine, so that's not the problem.
ben604 Posted May 30, 2012 Author Posted May 30, 2012 Sorry Steve, I wasn't ignoring you! %%a gave an error, %a seems to be getting at least half the job done!
plexer Posted May 30, 2012 Posted May 30, 2012 In a batch file: echo off for /f "tokens=1,2 delims=, " %%a in (c:\scripts\input.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b Input file: moodle,00:00:00:00:00 test1,01:00:00:00:00 test2,02:00:00:00:00 Emulates the output that you are expecting for me Ben
plexer Posted May 30, 2012 Posted May 30, 2012 %a is setting fine, so that's not the problem. It will do if run from the command line but in a batch file it needs to be %% If a% is setting ok from the command line there must be an errorr in the input file. Ben
X-13 Posted May 30, 2012 Posted May 30, 2012 In a batch file: echo off for /f "tokens=1,2 delims=, " %%a in (c:\scripts\input.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b Input file: moodle,00:00:00:00:00 test1,01:00:00:00:00 test2,02:00:00:00:00 Emulates the output that you are expecting for me Ben Strangly, it isn't working properly for me. All it's doing it parsing the file path...
Steve21 Posted May 30, 2012 Posted May 30, 2012 Works fine here.. you're using bat file? not command line? C:\test>test1.bat C:\test>echo off wdsutil /Set-Device /Device:moodle /ID:00:00:00:00:00 wdsutil /Set-Device /Device:test1 /ID:01:00:00:00:00 wdsutil /Set-Device /Device:test2 /ID:02:00:00:00:00 C:\test> Steve 1
ben604 Posted May 30, 2012 Author Posted May 30, 2012 Works fine here.. you're using bat file? not command line? Steve Hi Steve, I was working from cmd, I'll create a batch, see how it get on. Ben
X-13 Posted May 30, 2012 Posted May 30, 2012 (edited) Strangly, it isn't working properly for me. All it's doing it parsing the file path... Ok, so I just tried with @plexer's input file... and it works fine. Seems my CSV file is dodgy... Stupid MyMaths. [i used the MyMaths login setup CSV to test.] Le EDIT: Batch files don't like parsing files with UNC paths... FACT. [CTRL+C/CTRL+V the file to my admin account makes it work fine...] So much shenanigans... But... yeah. It's looking like your CSV is borked. Edited May 30, 2012 by X-13 1
ben604 Posted May 30, 2012 Author Posted May 30, 2012 I've attached a zip with the two files I'm using. I'm not executing it on the server with my admin creds on an elevated cmd...still no joy.files.zip
plexer Posted May 30, 2012 Posted May 30, 2012 for /f "tokens=1,2 delims=, " %%a on (c:\scripts\fog.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b is wrong it should be: for /f "tokens=1,2 delims=, " %%a in (c:\scripts\fog.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b You had on and not in before the input file. Ben 1
plexer Posted May 30, 2012 Posted May 30, 2012 damn beaten to it But yes change the line as shown and it runs fine. Ben
ben604 Posted May 30, 2012 Author Posted May 30, 2012 for /f "tokens=1,2 delims=, " %%a on (c:\scripts\fog.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b is wrong it should be: for /f "tokens=1,2 delims=, " %%a in (c:\scripts\fog.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b You had on and not in before the input file. Ben durrrrrrr my mind is meltingggg.....
ben604 Posted May 30, 2012 Author Posted May 30, 2012 magnificent, it works a treat! Thanks for the help everyone!
X-13 Posted May 30, 2012 Posted May 30, 2012 (edited) I've attached a zip with the two files I'm using. I'm not executing it on the server with my admin creds on an elevated cmd...still no joy. Change "on" to "in" and remove the space after delims=, It works fine. Le EDIT: Well and truly ninja'd. But yes change the line as shown and it runs fine. I also had to take out the space. It was setting the delimiters to ,[space] so everything was being set as %%a. Edited May 30, 2012 by X-13 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now