|
| |||||||||
| Tags: batch, dsmod, text |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| DSMOD from batch and text file
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? |
|
#2
| |||
| |||
| Re: DSMOD from batch and text file "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 -- |
|
#3
| |||
| |||
| RE: DSMOD from batch and text file
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? |
|
#4
| |||
| |||
| Re: DSMOD from batch and text file
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 > -- > > > . > |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "DSMOD from batch and text file" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Editing text file using a batch file | beelow | Software Development | 8 | 09-03-2010 12:27 AM |
| Replace text string using batch file | jean-paul martell | Operating Systems | 2 | 23-06-2009 02:18 PM |
| batch file to split multiple text files in half. | yammyguy | Windows Server Help | 8 | 11-05-2009 07:19 PM |
| Batch Script Text file parse | tator.usenet@gmail.com | Windows Server Help | 5 | 25-03-2009 03:12 AM |
| Batch Script to parse lines in text file | jntoner1@gmail.com | Windows Server Help | 8 | 28-01-2009 04:38 AM |