LeightonJames Posted March 11, 2016 Posted March 11, 2016 Hi All Powershell Noob here but I need to understand why this script fails when running against remote machines. (IP is a placeholder obv.) #################################################### # Change these values to the appropriate values in your environment $PrinterIP = "10.10.10.10" $PrinterPort = "9100" $PrinterPortName = "IP_" + $PrinterIP $DriverName = "Xerox WorkCentre 7855 PCL6" $DriverPath = "C:\Temp\Photocopier" $DriverInf = "C:\Temp\Photocopier\x2DSPYX.inf" $PrinterCaption = "Colour Photocopier" #################################################### ### ComputerList Option 1 ### # $ComputerList = $env:COMPUTERNAME ### ComputerList Option 2 ### $ComputerList = @() Import-Csv “C:\Temp\ComputersThatNeedPrinters.csv” | ` % {$ComputerList += $_.Computer} Function CreatePrinterPort { param ($PrinterIP, $PrinterPort, $PrinterPortName, $ComputerName) $wmi = [wmiclass]”\\$ComputerName\root\cimv2:win32_tcpipPrinterPort” $wmi.psbase.scope.options.enablePrivileges = $true $Port = $wmi.createInstance() $Port.name = $PrinterPortName $Port.hostAddress = $PrinterIP $Port.portNumber = $PrinterPort $Port.SNMPEnabled = $false $Port.Protocol = 1 $Port.put() } Function InstallPrinterDriver { Param ($DriverName, $DriverPath, $DriverInf, $ComputerName) $wmi = [wmiclass]”\\$ComputerName\Root\cimv2:Win32_PrinterDriver” $wmi.psbase.scope.options.enablePrivileges = $true $wmi.psbase.Scope.Options.Impersonation = ` [system.Management.ImpersonationLevel]::Impersonate $Driver = $wmi.CreateInstance() $Driver.Name = $DriverName $Driver.DriverPath = $DriverPath $Driver.InfName = $DriverInf $wmi.AddPrinterDriver($Driver) $wmi.Put() } Function CreatePrinter { param ($PrinterCaption, $PrinterPortName, $DriverName, $ComputerName) $wmi = ([WMIClass]”\\$ComputerName\Root\cimv2:Win32_Printer”) $Printer = $wmi.CreateInstance() $Printer.Caption = $PrinterCaption $Printer.DriverName = $DriverName $Printer.PortName = $PrinterPortName $Printer.DeviceID = $PrinterCaption $Printer.Put() } foreach ($computer in $ComputerList) { CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort ` -PrinterPortName $PrinterPortName -ComputerName $computer InstallPrinterDriver -DriverName $DriverName -DriverPath ` $DriverPath -DriverInf $DriverInf -ComputerName $computer CreatePrinter -PrinterPortName $PrinterPortName -DriverName ` $DriverName -PrinterCaption $PrinterCaption -ComputerName $computer } #################################################### If I run this against a single machine (uncommmenting # $ComputerList = $env:COMPUTERNAME) it works fine. No drama and everything is hunky dory. If I run it against a list of remote machines using the settings above then I get this error: Exception calling "Put" with "0" argument(s): "Generic failure " At D:\GPInstall\Printer_Install_Scripts\ColourPhotocopier\ColourPhotocopier.ps1:56 char:1 + $Printer.Put() + ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ( [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException This happens everytime Has anyone got a working Powershell script that accomplishes this task or knows how to get this working? I have even put the relevant files into a network share and tried running it from there (changing file paths accordingly obviously). Cheers
mukz Posted March 12, 2016 Posted March 12, 2016 Any reason your not using GPO? Are you trying to do this on demand?
LeightonJames Posted March 15, 2016 Author Posted March 15, 2016 Sorry for the delayed response. We don't run print servers on the network. All the printers are installed using TCP/IP ports only. If I can get this script to work I can then add it to GP and install the printers automatically.
mukz Posted March 15, 2016 Posted March 15, 2016 Hi mate, I can have a look at the script when I'm back from my leave. But call me old fashioned - the headache alleviated by having a print server plus gpo is second to none.
LeightonJames Posted March 17, 2016 Author Posted March 17, 2016 I agree, unfortunately the powers that be don't want us to install print servers on site as we have over 50 locations to look after, and they fear we would be forever restarting spooler services on the servers.
mukz Posted March 17, 2016 Posted March 17, 2016 Hi Mate, I totally understand. in the script swap the following: $DriverPath = "C:\Temp\Photocopier" $DriverInf = "C:\Temp\Photocopier\x2DSPYX.inf" With $DriverPath = “\\UNC_Path\Photocopier\Drivers” $DriverInf = “\\UNC_Path\Photocopier\Drivers\x2DSPYX.inf” Let me know how you get on.
LeightonJames Posted March 17, 2016 Author Posted March 17, 2016 Cheers. I'll give it a whirl this afternoon
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now