Hey guys
im total newbie and got this from the web; struggeling now with put(). It says “Connection refused”. WMI installed;DCOM activated…
####################################################
Change these values to the appropriate values in your environment
$ComputerName = “windows01”
$PrinterIP = “11.10.10.10”
$PrinterPort = “9101”
$PrinterPortName = “IP_” + $PrinterIP
$DriverName = “Sharp MX-3100N - scriptinstalled”
$DriverPath = “\localhost\share\MX3100\German\PCL6\64bit”
$DriverInf = “\localhost\share\MX3100\German\PCL6\64bit\sn0emdeu.inf”
$PrinterCaption = “SWLaser2”
####################################################
ComputerList Option 1
$ComputerList = @(“windows01”)
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
}
####################################################
Thanks!
edit:
[otherLANG]Ausnahme beim Aufrufen von “Put” mit 0 Argument(en): "Allgemeiner Fehler "[/otherLANG]
In C:\Users\windows\Desktop\addprinter.ps1:57 Zeichen:1
- $Printer.Put()
-
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException