#Powershell Printer Installation and Log. Would like thoughts on how to improve the script?

1 messages · Page 1 of 1 (latest)

rose marsh
#

I for the most part figured out everything that was preventing me from doing all these tasks when I run the script locally. However, when I try to do it to a remote machine it takes so long. It would not be worth it working on over 1000+ printers. 1 off's ok but it must run faster. Not sure how to do this other than going to each server and only running the script locally on each server directly. I would say this script is about 80% done but the everything I am wanting it to do exists. mainly troubleshooting for what I did not accommodate for or logic errors and speed.

High level here is what the script does:
1 allows me to install the printer to multiple print servers. Enabling sharing and publishing.

  • while checking if the driver and port exists and if not it installs them
    -then it applies the Acceptable ACL's to the printers (this script does not like to run remotely due to permission issues but works fine locally.)
    -Logging all activity

what is killing me is things like
get-printer -computer $somecomputer
get-printerport -computer $somecomputer
get-printerdriver -computer $somecomputer

all of which take 15 to 30 min to return results over a 500gb mpls circuit between primary and backup site and even if the second machine is in the local site.

But also wanted to get input from other on things I could do to improve the logic flow.

tidal trout
#

wanted to dig in - but literally stopped on unzipping ^^

what you are doing there seems a lot of pain for printers - multiple printservers?
why ? ...

id personally recommend using the printerservers the printers themselves offer and simply distribute a printer-setup to the (now all) clients - done

you double/triple the pain for no benefits afaikt

#

or vice versa: centralize and distribute 1 virtual printer - via cups or universal print or whatever solution is available around

rose marsh
#

just incase the zip did not work.

#

I agree there is a lot of pain and like this script works fine if i run it locally.... it is a pain when i have the script do it to a remote computer so I will have to just use it locally for now until I can figure out ways to improve.

#

I agree a centralized print server would be beneficial but I am working in a environment with about 25 print servers for over 1000+ printers.

Until management agrees to a redesign of printers this is what I am dealing with. Of thouse 25 print servers, 4x of them have all the printers on them. so I am trying to simplify deployemnt with a script instead of manually using the print manager on the server or the Remote Server Admin Tools print manager.

#

also when backing up and restoring printer servers queues it becomes a pain when all the printers do not restore properly... then you have to go and manually install or find the printer that is breaking things in the migration.

#

so I wanted a script that would individually read the configuration and install the printers to a given print server.

#

this is just 1 reason. The other reason is there is a lot of steps in applying printer ACL's to all the printers correctly by dept. There is no real tool for this, it is either all or you manually go 1 by 1 and configure.

#

then to ensure comments and location and drivers are the same on all the print servers and not different between print servers....

#

just a little back ground.

tidal trout
#

y i feel the pain
allready got frustrated with ~20printers on 3 business locations ... thats why i primarily would avoid a deployment like this (and did for myself)
either 1 printerserver or none - everything else gets totally out of hands and simply not worth the effort for a output device (from my perspective)

teal prawn
#

Because the left side of comparison decides on what types to coerce to, you want null to be on the left, else you can get unexpected results

= if ($PrinterSNMPInfo.PagesPrintedCountTotal -eq $Null) {''}

= if ($null -eq $PrinterSNMPInfo.PagesPrintedCountTotal) {''}
teal prawn
#

For your blocks of code like this,

$this.PageTotalCount = if ($PrinterSNMPInfo.PagesPrintedCountTotal -eq $Null) { '' } else { $PrinterSNMPInfo.PagesPrintedCountTotal }
$this.PageColorCount = if ($PrinterSNMPInfo.PagesPrintedColorCount -eq $Null) { '' } else { $PrinterSNMPInfo.PagesPrintedColorCount }
$this.PageBlackCount = if ($PrinterSNMPInfo.PagesPrintedBlackCount -eq $Null) { '' } else { $PrinterSNMPInfo.PagesPrintedBlackCount }

if you're using Pwsh then you can use

class PrinterDetailClass { 
    [string]$PageTotalCount
    [string]$PageColorCount
    [string]$PageBlackCount

    PrinterDetailClass( [string] $PrinterNameIn, [string] $PrinterServerIn) {
        $this.PageTotalCount = ($PrinterSNMPInfo)?.PagesPrintedCountTotal ?? ''
        $this.PageColorCount = ($PrinterSNMPInfo)?.PagesPrintedColorCount ?? '' 
        $this.PageBlackCount = ($PrinterSNMPInfo)?.PagesPrintedBlackCount ?? '' 
    } 
}

Because it's a class field, the ?? '' is redundant, but, I'd keep it anyway to keep the intent explicit

#

If you're not, you can use

if( [string]::IsNullOrEmpty( $PrinterSNMPInfo.PagesPrintedCountTotal ) { $this.PageTotalCount = $PrinterSNMPInfo.PagesPrintedCountTotal } 

# or depending what you want to be false, 
[string]::IsNullOrWhiteSpace( )

rose marsh
#

Thanks I will make those adjustments...