Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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

Posted

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?

  • Thanks 1
Posted
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...!

Posted
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

  • Thanks 1
Posted (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 by X-13
  • Thanks 1
Posted

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

Posted
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 %% ! :D

 

Steve

Posted

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

Posted
%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

Posted
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...

Posted

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

  • Thanks 1
Posted
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

Posted (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 by X-13
  • Thanks 1
Posted

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

  • Thanks 1
Posted
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.....

Posted (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 by X-13
  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...