Solved

Using dsmod user with for /f - Inserting multiple users

Posted on 2011-03-17
5
1,314 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:G_M
  • 2
  • 2
5 Comments
 
LVL 26

Expert Comment

by:farhankazi
ID: 35162896
Change following line

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

with

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

Hope this helps!
Farhan
0
 

Author Comment

by:G_M
ID: 35163158
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
0
 
LVL 26

Accepted Solution

by:
farhankazi earned 500 total points
ID: 35163875
What about this:
for /f "delims=*" %%a IN ('TYPE %Users%') do (
0
 
LVL 51

Expert Comment

by:Netman66
ID: 35166055
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 (

0
 

Author Comment

by:G_M
ID: 35170225
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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now