-1

I am creating a batch file that will add Network Printers based on your location. The script works fine in PS when I have my admin rights, but I am not sure how to add admin rights when adding a printer. I have the following code, and it is repeated several times in the file with different printer information to add all printers for that area.

Add-PrinterDriver -Name "HP LaserJet 600 M601 M602 M603 PCL6"
Add-PrinterPort -Name "IP" -PrinterHostAddress "IP"
Add-Printer -Name "10139 Printer - Production" -DriverName "HP LaserJet 600 M601 M602 M603 PCL6" -Shared -ShareName "ProdPrinter" -PortName "IP"

I want to be able to run the batch file on any pc and just work, nothing else. no display.

  • I'm not sure what the question is here. The title says *not recognizing* and *batch file*, but the text makes no mention of an issue related to *not recognizing* or a batch file. Please [edit] to clarify exactly what you're asking, which appears to be *how to enable admin privileges from a Powershell script*, which is totally different from anything you're currently asking. – Ken White May 24 '19 at 12:55
  • I'm confused with this question, you're showing me a PS script (ps1) but in the title you state you're running a batch script (.bat) - can you clarify on this, please. – Matthew May 24 '19 at 13:14
  • One PowerShell is not a batch file. Batch files require cmd.exe and a file with a .cmd / .bat extension. Of course PowerShell is a .ps1 extension. Lastly, by default in Windows, non-Armin users cannot add printers, install software, make system -wide changes, unless you change the AD GPO to allow them to be able to. So, either give them the rights to do this AD, or set a scheduled task using the needed credentials for the targets. – postanote May 24 '19 at 18:30

1 Answers1

0

Considering you are using it as a .ps1 and not as a .bat.

You can hard-code credentials. But I wouldn't prefer it.

If you are interessted in this option look at this stackoverflow question.

Using PowerShell credentials without being prompted for a password

Hope it helps.

  • If your answer consists of nothing but a link to an existing question, you should be flagging this question as a duplicate of that post instead. – Ken White May 24 '19 at 16:10