G_M
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:
This is the error output I am getting:
Hope someone can help.
Cheers
G_M
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
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"
Hope someone can help.
Cheers
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
It still substitutes "C:\Temp\users.txt" for the %%a instead of the values in the users.txt
... stumped
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 (
for /f "delims=*" %%a in (users.txt) do (
ASKER
Fantastic, all works. This is the complete solution I'm working with.
Thank you for your help.
G_M
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
for /f %%a in ("%Users%") do (
with
for /f "delims=*" %%a in (%Users%) do (
Hope this helps!
Farhan