Link to home
Start Free TrialLog in
Avatar of G_M
G_MFlag for Australia

asked on

Using dsmod user with for /f - Inserting multiple users

Hey guys,

I seem to be having a lot of trouble with something I thought would be relatively easy. I am trying to use a list of users. I am having two issues:

1. I can run the command on the user from the CLI, however, as soon as I integrate the for /f it doesn't recognise the input.
2. I am yet to get this working with a user with a FQDN with a space in their CN

This is the code I have so far:

 
set Users=c:\temp\users.txt
(
pushd C:\Temp
for /f %%a in ("%Users%") do (
   dsmod user "CN=%%a,CN=Users,DC=roads,DC=vic,DC=gov,DC=au" -office testoffice
)
echo "%Users%"
popd
) >>dsmod.log 2>&1

Open in new window


This is the error output I am getting:

 
C:\temp>(dsmod user "CN=c:\temp\users.txt,CN=Users,DC=roads,DC=vic,DC=gov,DC=au" -office testoffice ) 
dsmod failed:Value for `Target object for this command' has incorrect format.
type dsmod /? for help."c:\temp\users.txt"

Open in new window


Hope someone can help.
Cheers
G_M
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Change following line

for /f %%a in ("%Users%") do (

with

for /f "delims=*" %%a in (%Users%) do (

Hope this helps!
Farhan
Avatar of G_M

ASKER

hmmm... the error goes away, however, the command still doesn't execute properly.

It still substitutes "C:\Temp\users.txt"  for the %%a instead of the values in the users.txt


... stumped
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Netman66
Yes, don't use a variable AND run the script from the same folder as the text file.

for /f "delims=*" %%a in (users.txt) do (

Avatar of G_M

ASKER

Fantastic, all works. This is the complete solution I'm working with.

Thank you for your help.
G_M

 
set Users=c:\temp\users.txt
set Office=Sunshine
pushd C:\Temp
(
for /f "delims=*" %%a IN ('TYPE %Users%') do (
   dsmod user "CN=%%a,OU=User Accounts,DC=cec,DC=cec,DC=cec,DC=au" -office "%Office%"
)) >>dsmod.log 2>&1
popd

Open in new window