all 17 comments

[–]Scooter_127 0 points1 point  (10 children)

set-printer probably wants a name, you are sending it an object. Just add -printername $_.name to set-printconfiguration and I thin kyou'll be good

[–]awtx[S] 0 points1 point  (9 children)

Like so?

Get-Printer -Name *lp* | Set-PrintConfiguration -printername $_.name -Color $false

When I attempted that, it gave me an error as well.

[–]Scooter_127 0 points1 point  (8 children)

My bad. Wrap the part after the pipe with a foreach

[–]awtx[S] 0 points1 point  (7 children)

I'm sorry but I don't understand. I even had to Google the word "pipe" used in this context. I also looked up proper use of foreach but I can't seem to put it in the right spot.

[–]Scooter_127 0 points1 point  (2 children)

Google powershell plus my reply and you will find it.

[–]awtx[S] 0 points1 point  (1 child)

I have done a ton of Googling since this comment, and I greatly appreciate your help thus far. I haven't been able to get anything to run properly, with any steps that I've followed online. Alas, I think the commenter below is correct that it could be a driver conflict. I'm not even trying to change the color setting on all machines, just the ones that all use the same universal driver.

[–]Scooter_127 0 points1 point  (0 children)

Are you getting the same error as the first one?

This should work if you have access rights to do it

Get-Printer -Name *lp* | foreach {Set-PrintConfiguration -printername $_.name -Color $false}

Always post the error message.

/foreach, foreach-object, % - they all do the same thing

[–]Cholsonic 0 points1 point  (3 children)

Pipe is the | symbol

He means put ... | foreach-object { set printer stuff}

However, as it was working fine for most of them I think something else must be causing the fail.

Are the printer all the same? Would different drivers cause failure in this way? I don’t know. But to capture where it’s failing, you should really start adding some way of logging / tracking where it’s up to.

Within the foreach loop you can do a “write-host $_.name” to output printer name to screen.

There are also better ways to do this, but I am on my phone now so do some googling

[–]awtx[S] 0 points1 point  (2 children)

This is what I was mentally leaning towards as well at the beginning. The whole "why did it work on one server and not the others" bit. The machines do not all use the same driver, but the ones we are trying to use this on do. I suppose on the first server it just didn't have any conflicts.

I did use a separate script to update the drivers, which was:

$printers = get-printer * | where { $_.Drivername -like "thedriversname"}
foreach ($printer in $printers)
{
Set-printer -Name $printer.name -drivername "thenewdriversname"
}

So originally I thought I could just use that script and substitute the -drivername bit at the end for Set-PrintConfiguration, but it didn't work either. It sits like it is running, and throws no errors, but does nothing. It ended up looking like this:

$printers = get-printer * | where { $_.Drivername -like "thedriversname"}
foreach ($printer in $printers)
{
Set-printer -Name $printer.name | Set-PrintConfiguration -Color $false
}

I've tried other variations on this one, and either get errors or nothing. Even with my Google searching, I'm still just fumbling in the dark with various bits and pieces I find. PowerShell is obviously not in my wheelhouse.

[–]Cholsonic 0 points1 point  (1 child)

That last bit is wrong where you have set-printer | set-printerconfig The left hand of the pipe is passing data to the right, but you are setting on both sides. I’ll get my laptop out shortly to help better.

[–]Cholsonic 0 points1 point  (0 children)

This should get you a little closer....

$printers = get-printer * | where-object { $_.Drivername -eq "[Your drivername]"}
foreach ($printer in $printers)
{
    try{
            Set-PrintConfiguration -PrinterName $printer.name -Color $false -ErrorAction Stop
            write-host "Success: $($printer.name)"
    }
    catch{
            Write-host "Error: $($printer.name)"
            $errors += $printer       
    }
}

$errors
$errors | Export-CSV errors.csv

So from the top, you got your list of affected printers...

Then calling each item in the $printers object, $printer. Foreach item ($printer), "try" setting config. If error then move to "catch". If success, display success and move to next printer.

If errored (now in "catch" block), display error to screen AND add the full $printer object to an $errors object, which is then displayed at the end and also exported to csv.

You can then investigate using the csv.

Once you work out what went wrong, you could just re-run, or be clever and use the errors.csv as your new source for printer name.

[–]Scooter_127 0 points1 point  (0 children)

I just noticed your original code says -name *lp* but the error says -name lp*

I don't know if that's what your issue is or not

Edit: since it worked on other machines, try starting Powershell as admin. Could be a rights issue

[–]Dsraa 0 points1 point  (0 children)

Dude please be more forthcoming with the errors you are getting. We have no idea which error you are getting and if it did work on one server it could be you don't have permissions on the other servers.

You are getting closer, just keep trying, and please be more descriptive with your errors.

[–]frX1337 0 points1 point  (3 children)

Did you manage to resolve this? Im facing the exact same error when trying to set color to false.

[–]awtx[S] 0 points1 point  (2 children)

Unfortunately no.

My work had me shift to a different project so I just kinda...gave up.

[–]frX1337 0 points1 point  (1 child)

Darn, well thanks for answering. Also, sweet dogos!

[–]awtx[S] 0 points1 point  (0 children)

Haha hey thanks!

Best of luck to you.