Forum Search:
Forum.Brain-Cluster.com: Brain Cluster Technical Forum
Ultimate forum for Technical Discussions

Home » Microsoft » Windows Server » Active Directory » DSMOD from batch and text file
DSMOD from batch and text file [message #403951] Wed, 03 March 2010 08:11 Go to next message
Pete Jones  is currently offline Pete Jones
Messages: 7
Registered: March 2010
Junior Member
I am trying to run a batch file that will disable user accounts using a text
file.

--Batch file--
@echo off
if {%1}=={} @echo Syntax: disableDNs FileName&goto :EOF
if not exist %1 @echo Syntax: disableDNs %1 not found.&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set file=%1
@echo.
for /f "Tokens=*" %%u in ('type %file%') do (
set user=%%u
set user="!user:"=!"
@echo DSMOD USER !user! -desc Disabled -disabled yes
DSMOD USER !user! -desc Disabled -disabled yes
@echo.
)
endlocal

--text file--

"CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com"
"CN=Madeup,CN=Name,OU=Test,DC=test,DC=com"

etc

It fails each object with the message:

dsmod failed:CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com\ :A referral
was sent from the server.


ANyone have any ideas?
Re: DSMOD from batch and text file [message #404013 is a reply to message #403951] Wed, 03 March 2010 09:30 Go to previous messageGo to next message
rlmueller-nospam  is currently offline rlmueller-nospam  United States
Messages: 292
Registered: July 2009
Senior Member
"Pete Jones" <PeteJones@discussions.microsoft.com> wrote in message
news:FC128F85-8A14-474C-ABB1-A48715F976C4@microsoft.com...
>I am trying to run a batch file that will disable user accounts using a
>text
> file.
>
> --Batch file--
> @echo off
> if {%1}=={} @echo Syntax: disableDNs FileName&goto :EOF
> if not exist %1 @echo Syntax: disableDNs %1 not found.&goto :EOF
> setlocal ENABLEDELAYEDEXPANSION
> set file=%1
> @echo.
> for /f "Tokens=*" %%u in ('type %file%') do (
> set user=%%u
> set user="!user:"=!"
> @echo DSMOD USER !user! -desc Disabled -disabled yes
> DSMOD USER !user! -desc Disabled -disabled yes
> @echo.
> )
> endlocal
>
> --text file--
>
> "CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com"
> "CN=Madeup,CN=Name,OU=Test,DC=test,DC=com"
>
> etc
>
> It fails each object with the message:
>
> dsmod failed:CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com\ :A referral
> was sent from the server.
>
>
> ANyone have any ideas?

The Distinguished Name (DN) of the user looks wrong, which would account for
the error message. Assuming the user object is in the "cn=User" container
(and not in an OU), and the Common Name of the user is "Lastname,
Firstname", then the DN could be:

cn=Lastname\, Firstname,cn=Users,dc=Test,dc=com

Note if the Common Name has an embedded comma, it must be escaped with the
backslash escape character. Does this help?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
RE: DSMOD from batch and text file [message #404014 is a reply to message #403951] Wed, 03 March 2010 09:37 Go to previous messageGo to next message
Pete Jones  is currently offline Pete Jones
Messages: 7
Registered: March 2010
Junior Member
So I solved it, and I know what the problem was, but I don't know why what I
did worked. I can guess, but would prefer an explanation from someone who
knows.

I removed this line: set user="!user:"=!"

My guess is that it was designed to put the name in quotes, Because my text
file already had them in quotes, it was removing the last quote, putting a
space in, and then putting down it's own quote.

So instead of DSMOD USER "CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com"

it became DSMOD USER "CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com "

which threw up the error.


Why? And bonus points for someone who can fix the line so it adds quotes
when needed, and leaves them alone when they are already there.
--



"Pete Jones" wrote:

> I am trying to run a batch file that will disable user accounts using a text
> file.
>
> --Batch file--
> @echo off
> if {%1}=={} @echo Syntax: disableDNs FileName&goto :EOF
> if not exist %1 @echo Syntax: disableDNs %1 not found.&goto :EOF
> setlocal ENABLEDELAYEDEXPANSION
> set file=%1
> @echo.
> for /f "Tokens=*" %%u in ('type %file%') do (
> set user=%%u
> set user="!user:"=!"
> @echo DSMOD USER !user! -desc Disabled -disabled yes
> DSMOD USER !user! -desc Disabled -disabled yes
> @echo.
> )
> endlocal
>
> --text file--
>
> "CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com"
> "CN=Madeup,CN=Name,OU=Test,DC=test,DC=com"
>
> etc
>
> It fails each object with the message:
>
> dsmod failed:CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com\ :A referral
> was sent from the server.
>
>
> ANyone have any ideas?
Re: DSMOD from batch and text file [message #404214 is a reply to message #404013] Wed, 03 March 2010 13:12 Go to previous message
Pete Jones  is currently offline Pete Jones
Messages: 7
Registered: March 2010
Junior Member
Not quite. I was giving those as examples, so if they aren't quite correctly
formatted that is my error on here, but not on the coding.

Turns out it was a line of code that replaced the last " with a space and
then the ". Removing that line fixes it, although since it is meant to
encapsulate the DN with quotes, I need to make sure that the quotes are in
there or it will break again.

I explain it better in my first reply to my own question.
--


"Richard Mueller [MVP]" wrote:

>
> "Pete Jones" <PeteJones@discussions.microsoft.com> wrote in message
> news:FC128F85-8A14-474C-ABB1-A48715F976C4@microsoft.com...
> >I am trying to run a batch file that will disable user accounts using a
> >text
> > file.
> >
> > --Batch file--
> > @echo off
> > if {%1}=={} @echo Syntax: disableDNs FileName&goto :EOF
> > if not exist %1 @echo Syntax: disableDNs %1 not found.&goto :EOF
> > setlocal ENABLEDELAYEDEXPANSION
> > set file=%1
> > @echo.
> > for /f "Tokens=*" %%u in ('type %file%') do (
> > set user=%%u
> > set user="!user:"=!"
> > @echo DSMOD USER !user! -desc Disabled -disabled yes
> > DSMOD USER !user! -desc Disabled -disabled yes
> > @echo.
> > )
> > endlocal
> >
> > --text file--
> >
> > "CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com"
> > "CN=Madeup,CN=Name,OU=Test,DC=test,DC=com"
> >
> > etc
> >
> > It fails each object with the message:
> >
> > dsmod failed:CN=Lastname,CN=Firstname,CN=Users,DC=test,DC=com\ :A referral
> > was sent from the server.
> >
> >
> > ANyone have any ideas?
>
> The Distinguished Name (DN) of the user looks wrong, which would account for
> the error message. Assuming the user object is in the "cn=User" container
> (and not in an OU), and the Common Name of the user is "Lastname,
> Firstname", then the DN could be:
>
> cn=Lastname\, Firstname,cn=Users,dc=Test,dc=com
>
> Note if the Common Name has an embedded comma, it must be escaped with the
> backslash escape character. Does this help?
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
> .
>
Previous Topic:Account lock out threshold
Next Topic:DHCP permissions
Goto Forum:
  


Current Time: Sat Jan 20 08:29:08 MST 2018

Total time taken to generate the page: 0.06640 seconds
.:: Contact :: Home ::Sitemap::.

Powered by: FUDforum 3.0.0RC2.
Copyright ©2001-2009 FUDforum Bulletin Board Software