We help IT Professionals succeed at work.
Get Started

pass username and password in batch file

Last Modified: 2019-12-28
pass username and password in batch file

I have this Script that adds a printer on each computer listed on text file , then at the end it calls a powershell, printer.ps1 that enables on the printer the option "Print Directly to printer"

Everything works fine.
I would like to run the script from my computer which is joined to the Domain against the computers listed on the text file which are not joined to the domain. So I need to pass username and password on this script ..the remote computers all have the same local Administrator account and password of Pass2020.

@echo off
for /f %%a in (CompPrinterConf.txt) do (
@echo starting pnpport on %%a

 cscript.exe "C:\windows\system32\Printing_Admin_Scripts\en-US\prnport.vbs" -a  -s %%a -r "AAAA" -h hostname -o raw -n 9100
@echo Waiting 5 seconds
timeout 5
@echo starting setting MyPrinter on %%a
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a  -p "XXXX-YYYY" -m "HP Universal Printing PCL 6" -r "AAAA"  -s %%a
REM Not really needed, because the script will continue with the next machine
REM timeout 5

@echo starting powershell
PowerShell.exe -ExecutionPolicy Bypass -Command  c:\Scripts\printer.ps1
REM timeout 5

Open in new window

Watch Question
End-user support
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE