I have a situation. I'm installing network printer on remote desktops using a batch file that calls up a Powershell script, but after printer is installed on the remote desktop, Powershell returns nothing - so my batch file wont be able to continue...I must manually hit ENTER twice to make it echo DONE and run the rest of the scripts. Any idea why?
@echo off
Copy /Y "\\AddPrinter\AddPrinter.ps1" "C:\scripts"
powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1"
Echo DONE
Del /F /Q "C:\ntfs3\scripts\AddPrinter.ps1"
This is my powershell script, I even put a exit in the end of script, but powershell on remote pc just wont exit.....so it will not return to batch
$PrinterPath = "\\server-01\Printer0101"
$net = new-Object -com WScript.Network
$net.AddWindowsPrinterConnection($PrinterPath)
exit
BTW, I m using psexec to call up this batch file with a txt file containing all pc names.
psexec @%1 -u admin -p xxxxxx -c -f "C:\AAA\AddPrinter.bat"
I did some research, some one said need to use call with %1 > null to make Powershell return to batch. But it does not work either.
Call powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1" %1 > null
I could only use batch command to install printer, but after installation, the new printer always setup as a default printer. but if use powershell to install it, it wont change default printer on remote desktop.
rundll32 printui.dll PrintUIEntry /ga /n\\server-01\printer0101
Hint please.
Callin the batch file for me. Maybe add the-NoProfileswitch to your powershell.exe line? What account are you running this under?