+ Post New Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
Scripts Thread, FOR /F Loop batch help... in Coding and Web Development; I'm trying to import our machines from Fog into our new AD using this script I found on the interwebs: ...
  1. #1
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    291
    Thank Post
    78
    Thanked 24 Times in 20 Posts
    Rep Power
    18

    FOR /F Loop batch help...

    I'm trying to import our machines from Fog into our new AD using this script I found on the interwebs:

    Code:
    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

  2. IDG Tech News
  3. #2

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    5,224
    Thank Post
    324
    Thanked 929 Times in 662 Posts
    Blog Entries
    18
    Rep Power
    458
    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?

  4. Thanks to X-13 from:

    ben604 (30th May 2012)

  5. #3
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    291
    Thank Post
    78
    Thanked 24 Times in 20 Posts
    Rep Power
    18
    Quote Originally Posted by X-13 View Post
    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...!

  6. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,262
    Thank Post
    302
    Thanked 417 Times in 389 Posts
    Rep Power
    159
    Quote Originally Posted by ben604 View Post
    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

    Code:
    for /F "tokens=1,2 delims=," %%1 in (ahosts.txt) do echo %%1 %%2
    Note double %%

    Steve

  7. Thanks to Steve21 from:

    ben604 (30th May 2012)

  8. #5

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    5,224
    Thank Post
    324
    Thanked 929 Times in 662 Posts
    Blog Entries
    18
    Rep Power
    458
    Quote Originally Posted by ben604 View Post
    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.


    Quote Originally Posted by Steve21 View Post
    Not sure if it'll work as I didn't test it, but seesm you have same problem someone did yesterday

    Code:
    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.
    Last edited by X-13; 30th May 2012 at 08:54 AM.

  9. Thanks to X-13 from:

    ben604 (30th May 2012)

  10. #6

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,512
    Thank Post
    436
    Thanked 1,189 Times in 1,076 Posts
    Rep Power
    287
    Code:
    for /f "tokens=1,2 delims=, " %%a in (fogreport.csv) do wdsutil /Set-Device /Device:%%a /ID:%%b
    Should do it?

    Ben

  11. Thanks to plexer from:

    ben604 (30th May 2012)

  12. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,512
    Thank Post
    436
    Thanked 1,189 Times in 1,076 Posts
    Rep Power
    287
    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

  13. Thanks to plexer from:

    ben604 (30th May 2012)

  14. #8
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    291
    Thank Post
    78
    Thanked 24 Times in 20 Posts
    Rep Power
    18
    Thanks guys, tried all those variations with no results...

    Code:
    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

  15. #9

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,262
    Thank Post
    302
    Thanked 417 Times in 389 Posts
    Rep Power
    159
    Quote Originally Posted by ben604 View Post
    Thanks guys, tried all those variations with no results...

    Code:
    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

  16. #10

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    5,224
    Thank Post
    324
    Thanked 929 Times in 662 Posts
    Blog Entries
    18
    Rep Power
    458
    Quote Originally Posted by Steve21 View Post
    Because you ignored all of us
    Double %% !

    Steve
    %a is setting fine, so that's not the problem.

  17. #11
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    291
    Thank Post
    78
    Thanked 24 Times in 20 Posts
    Rep Power
    18
    Sorry Steve, I wasn't ignoring you!

    %%a gave an error, %a seems to be getting at least half the job done!

  18. #12

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,512
    Thank Post
    436
    Thanked 1,189 Times in 1,076 Posts
    Rep Power
    287
    In a batch file:

    Code:
    echo off
    for /f "tokens=1,2 delims=, " %%a in (c:\scripts\input.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b
    Code:
    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

  19. #13

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,512
    Thank Post
    436
    Thanked 1,189 Times in 1,076 Posts
    Rep Power
    287
    Can you post some of your fogreport.csv???

    Ben

  20. #14

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,512
    Thank Post
    436
    Thanked 1,189 Times in 1,076 Posts
    Rep Power
    287
    Quote Originally Posted by X-13 View Post
    %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

  21. #15

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    5,224
    Thank Post
    324
    Thanked 929 Times in 662 Posts
    Blog Entries
    18
    Rep Power
    458
    Quote Originally Posted by plexer View Post
    In a batch file:

    Code:
    echo off
    for /f "tokens=1,2 delims=, " %%a in (c:\scripts\input.csv) do echo wdsutil /Set-Device /Device:%%a /ID:%%b
    Code:
    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...

SHARE:
+ Post New Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. For Next Loop in Batch File
    By barrystone in forum Scripts
    Replies: 2
    Last Post: 17th March 2011, 01:10 PM
  2. Replies: 1
    Last Post: 21st April 2010, 06:49 PM
  3. Robocopy and For loops in batch file
    By barrystone in forum Scripts
    Replies: 2
    Last Post: 14th April 2010, 02:07 PM
  4. Replies: 12
    Last Post: 11th October 2008, 11:37 PM
  5. Replies: 18
    Last Post: 19th September 2006, 08:38 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •