+ 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
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22

    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. #2

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,093
    Thank Post
    592
    Thanked 1,953 Times in 1,351 Posts
    Blog Entries
    19
    Rep Power
    814
    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?

  3. Thanks to X-13 from:

    ben604 (30th May 2012)

  4. #3
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    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...!

  5. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,694
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    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

  6. Thanks to Steve21 from:

    ben604 (30th May 2012)

  7. #5

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,093
    Thank Post
    592
    Thanked 1,953 Times in 1,351 Posts
    Blog Entries
    19
    Rep Power
    814
    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.

  8. Thanks to X-13 from:

    ben604 (30th May 2012)

  9. #6

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    Code:
    for /f "tokens=1,2 delims=, " %%a in (fogreport.csv) do wdsutil /Set-Device /Device:%%a /ID:%%b
    Should do it?

    Ben

  10. Thanks to plexer from:

    ben604 (30th May 2012)

  11. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  12. Thanks to plexer from:

    ben604 (30th May 2012)

  13. #8
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    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

  14. #9

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,694
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    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

  15. #10

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,093
    Thank Post
    592
    Thanked 1,953 Times in 1,351 Posts
    Blog Entries
    19
    Rep Power
    814
    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.

  16. #11
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    Sorry Steve, I wasn't ignoring you!

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

  17. #12

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  18. #13

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    Can you post some of your fogreport.csv???

    Ben

  19. #14

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,457
    Thank Post
    645
    Thanked 1,612 Times in 1,443 Posts
    Rep Power
    419
    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

  20. #15

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,093
    Thank Post
    592
    Thanked 1,953 Times in 1,351 Posts
    Blog Entries
    19
    Rep Power
    814
    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
  •