Really stumped here and I'm sure the answer is simple. Simply put, I'm creating a bunch of AD accounts based on input from a spreadsheet. I've been able to concatenate the fields into a DSADD command that I run each time a new user is onboarded. For example:
#echo off
dsadd user "CN=Bilbo Baggins,ou=Hobbiton,ou=Shire,ou=MiddleEarth,dc=lotr,dc=com" -fn Bilbo -ln Baggins -display "Bilbo Baggins" -upn bbaggins#lotr.com -pwd damnring! -email bbaggins#lotr.com -samid bbagins -mustchpwd no -disabled no
When I paste that into a cmd line and hit enter all is well, the AD account is created. I have hundreds of these - so I thought I would get fancy and put each of these commands on their own line and call it, oh, I don't know "add_all_users.bat". However when I call that from a command line or PS instance it errors out with "The syntax is incorrect".
What am I missing here?
Related
Part of my program's job is to create a new user account, elevate it to admin, and then run programs AS that user.
To do this, I would use the following code:
runas /user:hostname\AddedUserProfile /savecred program.exe
This works, but there is a problem. To use the runas command, the user you are running the program through, must have a password. Upon running the command, it asks you for that user's password. My program is supposed to run behind the scenes, and without the user being able to see it (Don't worry. I already have code that invisibly starts programs, so that is NOT the issue here). I can't find a way to automatically enter text into the password entry field (and yes, I know the password doesn't show visibly). I've tried having the program echo the password, and I've even tried to have it rerout the output of an echo command, into the input of the password field.
echo password | runas /user:hostname\AddedUserProfile /savecred program.exe
Even that doesn't work! it just gives me an error:
RUNAS ERROR: Unable to run - taskmgr.exe
-2147467259: Unspecified error
I really am at my wit's end on this one. If there is a way to do this other than runas, I'd LOVE to know! I'd prefer that it was using runas, though.
Edit:
It seems that the error is due to an incorrect password entry. I can't figure out why it would be entering it incorrectly, however. If I do not use the /savecred, then I get an error message that actually says that the password is incorrect.
Auto input password by using a pipe method like this:
echo PasswordHere | runas /user:hostname\AddedUserProfile /savecred program.exe
That mean, it will type "PasswordHere" when runas.exe need user input. I'm not tested it yet, so you have to try it out. I always use this "pipe" way to access my FTP server.
My apologies if the title was confusing. It should be fairly basic, but I cannot find a way to do this.
What i'm wanting to do is have a bat file prompt for an answer to a question and then surround that answer with another piece of code and either copy to the clipboard or after the connection.
Maybe it will make more sense if i give the code.
#echo off
set /p input ="what server would you like to connect to? (example srv02) :"
echo Myhome.%input%.com
pause
c:\program files\putty
the echo gives the correct response, but i would like to see if there is a way to paste this past the c:\program files\putty to connect to a server.
OR if there is a way to copy that response to the clipboard so the bat file would open putty (which it does now) and then you could just paste that response.
Or am i going about this the wrong way? thanks for the help!!
I'm not a PuTTY user, so I can't be sure - But I believe you are simply trying to pass the the server host that you want to connect to. I think the following will do what you asked:
"c:\program files\putty" %input%
or
"c:\program files\putty" Myhome.%input%.com
However, there are probably other command line options you need to really accomplish your goal.
You should learn the PuTTY command line arguments and options. I suspect a web search could find some tutorials or examples to get you started.
Perfect! That is what i ended up doing after a few more hours of research.
I came up with two different types of scripts as my company wants us to use a specific set of defaults for different servers.
#echo off
set /p input="what server would you like to connect to? : "
echo myhome.%input%.com| clip
echo ----
echo myhome.%input%.com has been copied to your clipboard,
echo you can now paste into the host name box in putty
echo -----
echo Press enter to open puTTY
echo -----
Pause
start c:\users\public\apps\putty.exe
Ended setting it to open putty instead of pasting because it should be defaulted settings, but not everyone kept it that way, of course.
Thanks for the assistance though!
I'm trying to send network credentials using Net Use command.
This is what I have:
#echo off
net use \\<serverName>\<shareFolder>\ passw0rd /USER:domain.com\UserName
PAUSE
This automatically inserts the username and Domain but for some reason not the password!!
I have tried it like this as well:
#echo off
net use \\<serverName>\<shareFolder>\ /USER:domain.com\UserName passw0rd
PAUSE
I have checked the paths I'm using and they definitely work. When i copy them out and paste in RUN they work.
Same goes for the username and passwords.
Everything in google search is purple cause I've clicked on all the links :/
Ok, I thought I had it...
I tried it like this:
#echo off
net use \\<serverName>\<shareFolder>\ <mapName> /USER:domain.com\UserName passw0rd
PAUSE
And it worked, but only because i entered the password before i tried it like this and then it remembered the password.
So I'm still looking for a way.
Please help.
Does the password contain special characters like % / ~ or similar characters with special meaning in batch files?
Yes, then enclose the password in double quotes.
Use also double quotes around UNC path and test if that makes a difference.
What I miss in all your net use commands is the device name usually specified left of UNC path to shared folder to map the shared folder to a drive letter. Therefore it could be that the password is interpreted as device name.
But according to your question you want to pass only the user credentials and password to be able to access the shared folder using UNC path. However, I suggest to test if it makes a difference really mapping the shared folder to a drive letter. I don't know if the password string is interpreted as device name if no device name specified and can't test it by myself at the moment.
#echo off
net use <MapDriveName> \\<serverName>\<ShareFolder>\ /PASSWORD:<Passw0rd> /USER:<UserName>
PAUSE
This one works for me. Finally :)
Hope this can help someone else as well.
net use Y: \server_name OR ipaddress\shared /user:domainname\%username%
OK, so I've never written a batch file before, but I have now got to the point where I need a batch file but as far as I'm aware it's going to be quite complex. So, basically this is what I need to do:
I need a batch file that will ask the user a few questions and then use their answers to complete a command to be run in the cmd.exe in Windows.
The command for my machine is as follows:
csvde -f C:\output -d "cn=Users,dc=test,dc=local" -r "(&(objectClass=user)(objectCategory=person))" -l "givenName, sn, objectGUID"
So I need a batch file that would ask the customer the info to go in the fields of the "dc=test" and the "dc=local" and then execute the finished command.
Any sort of help would be excellent, Thanks in advance.
:testlp
(set test=)
set /p test="Please enter test value "
if not defined test goto testlp
then use dc=%test% rather than dc=test
Leave you to figure out how to input local all by yourself...
Is there any way to change a username/account name using batch scripting? For example, change the username "testing" into "TESTING123", "Testing" or "testing123"? Thanks for your help.
There is a way to do this via wmic:
wmic useraccount where name="old_name" call rename "new_name"
As far as I am aware you can't do this in batch. You can create new accounts and delete old accounts but you can't rename them :)
For all user account stuff in batch type net user /? at a cmd prompt, or even just net /?.
Hope this helps.
If you are a windows 10 user, this worked for me.
wmic useraccount where name="%username%" call rename "myname4"
Change "myname4" to fit your use case.
Keep in mind, you should execute the batch as administrator or else this may not work. (It sometimes works, but not always, when not executed as administrator.)