Struggling with foreach

0

I'm rather new and, well, awful at this whole scripting thing: so any help would be appreciated.

Basically I am trying to create a PowerShell script that installs an undefined number of printers on an undefined number of computers. The computer names and printer names will come from local text files.

This is what I have so far:

$credentials = Get-Credential
$printerlist = Get-Content c:\setup\printers.txt
get-content c:\setup\names.txt | foreach-object {foreach($printer in $printerlist){rundll32 printui.dll PrintUIEntry /ge /c $_ /n  $printer}} 

EDIT: I am getting the error, unable to enumerate per machine printer connections operation could not be completed (error 0x0000007b) I have tried modifying the script anyway i can come up with, which is probably fewer ways than it should be.

powershell
printing
asked on Stack Overflow Nov 5, 2014 by Gleap • edited Nov 5, 2014 by Gleap

1 Answer

0

I don't think you have an issue with your foreach loop here.

I think it's just the usage of rundll32 printui.dll PrintUIEntry

Install printer:

rundll32 printui.dll,PrintUIEntry /in /c "\\COMPUTER_NAME" /n "\\PRINT_SERVER_NAME\PRINTER_NAME"

Sets default printer:

rundll32 printui.dll,PrintUIEntry /y /c "\\COMPUTER_NAME" /n "\\PRINT_SERVER_NAME\PRINTER_NAME"

Try installing with the /in individually for one computer from powershell console without your script to see if you still get the same error, could be a permission but I don't think so.

answered on Stack Overflow Nov 6, 2014 by Owen Davies

User contributions licensed under CC BY-SA 3.0