+ Post New Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
Scripts Thread, FOR /F Loop batch help... in Coding and Web Development; 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 ...
  1. #16

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    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

  2. Thanks to Steve21 from:

    ben604 (30th May 2012)

  3. #17
    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 Steve21 View Post
    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

  4. #18

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,245
    Thank Post
    607
    Thanked 2,023 Times in 1,392 Posts
    Blog Entries
    19
    Rep Power
    867
    Quote Originally Posted by X-13 View Post
    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.
    Last edited by X-13; 30th May 2012 at 10:06 AM.

  5. Thanks to X-13 from:

    ben604 (30th May 2012)

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

  7. #20

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    It's "in" not "on"

    Steve

  8. Thanks to Steve21 from:

    plexer (30th May 2012)

  9. #21

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,317
    Thank Post
    681
    Thanked 1,650 Times in 1,471 Posts
    Rep Power
    425
    Code:
    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:

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

  10. Thanks to plexer from:

    ben604 (30th May 2012)

  11. #22

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,317
    Thank Post
    681
    Thanked 1,650 Times in 1,471 Posts
    Rep Power
    425
    damn beaten to it

    But yes change the line as shown and it runs fine.

    Ben

  12. #23
    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 plexer View Post
    Code:
    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:

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

  13. #24
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    magnificent, it works a treat! Thanks for the help everyone!

  14. #25

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,245
    Thank Post
    607
    Thanked 2,023 Times in 1,392 Posts
    Blog Entries
    19
    Rep Power
    867
    Quote Originally Posted by ben604 View Post
    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.

    Quote Originally Posted by plexer View Post
    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.
    Last edited by X-13; 30th May 2012 at 10:41 AM.

  15. Thanks to X-13 from:

    plexer (30th May 2012)

  16. #26
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    So close...it's putting the right information in the right place, but I'm getting an error:

    An error occurred while trying to execute the command.
    Error Code: 0xC1040133
    Error Description: The specified computer could not be found.

    Putting them in individually works ok...peculiar...

  17. #27
    ben604's Avatar
    Join Date
    Jan 2010
    Posts
    314
    Thank Post
    81
    Thanked 29 Times in 24 Posts
    Rep Power
    22
    Right, worked it out. It should be /Add-Device not /Set-Device... all added to AD finally..!

  18. #28

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,317
    Thank Post
    681
    Thanked 1,650 Times in 1,471 Posts
    Rep Power
    425
    Glad you got there in the end.

    Amazing how a one line batch file can cause such head ache

    Ben

  19. #29

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,317
    Thank Post
    681
    Thanked 1,650 Times in 1,471 Posts
    Rep Power
    425
    You should see my 1 line batch file using For that searches students folder for a file matching criteria and then copies it to a destination within a subfolder named after that user.

    Ben

  20. #30

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,245
    Thank Post
    607
    Thanked 2,023 Times in 1,392 Posts
    Blog Entries
    19
    Rep Power
    867
    Quote Originally Posted by plexer View Post
    You should see my 1 line batch file using For that searches students folder for a file matching criteria and then copies it to a destination within a subfolder named after that user.

    Ben
    Should see = It's good...

    or

    Should see = It'll make your head spin?


    Also, well done @ben604

    Soon, you'll be scripting in your sleep.

SHARE:
+ Post New Thread
Page 2 of 3 FirstFirst 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
  •