0

Hey all was testing an idea with a script to help some of my student assistants with our Windows 10 roll out - so I'm making a restore script to compliment a backup one I made a while ago. It saves .csv's files on a public file share. I was attempting to reinstall all the network printers a user has on a .csv file by invoking rundll32 - it sees my list of printers and shows a installing printers window that stops shortly after that. None of the printers get added and its got me quite stumped. Seems like an easy enough process and could use some outside eyes with why this isnt working.

Thanks all!

$PrinterNames = Get-WmiObject -class win32_printer -ComputerName $env:COMPUTERNAME | where{$_.name -like '\\ps01*'} | select Name | Export-Csv -path C:\users\jheathe2\documents\Printer_export.csv 

$GetPrinter = Import-Csv -LiteralPath  C:\users\jheathe2\documents\Printer_export.csv
ForEach ($Printer in ($GetPrinter | %{$_.Name -like "\*"}))
{Invoke-Expression 'rundll32 printui.dll PrintUIEntry /in /q /n $($GetPrinter.name)'}

I excluded the pull from the fileshare part as my example because I wanted to know why rundll32 wasn't working more, as that's the barrier I am working with currently.

  • `ForEach ($Printer in ($GetPrinter | %{$_.Name -like "\*"}))` - `%` isn't `?`, the output of that pipeline which is fed to the ForEach is not a filtered list of printers, it's a lot of boolean true/falses "does the name match this pattern" for each printer. (It might be more clear if you had written the full names `foreach-object` or `where-object` instead of the aliases) – TessellatingHeckler Oct 17 '17 at 18:56
  • You could use [`(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection()`](https://learn.microsoft.com/en-us/powershell/scripting/getting-started/cookbooks/working-with-printers?view=powershell-5.1) instead of `printui.dll` – BenH Oct 17 '17 at 18:58

0 Answers0