0

複数のワークステーションにプリンターを追加する方法を見つけようとしています。これを達成できるはずの以下のスクリプトを見つけましたが、最初のスクリプトの下に含めるエラー ("Put" を "0" 引数で呼び出す例外: "Generic failure ") に遭遇しました。

####################################################
# Change these values to the appropriate values in your environment

$PrinterIP = "10.00.00.00"
$PrinterPort = "9100"
$PrinterPortName = "IP_" + $PrinterIP
$DriverName = "Xerox WorkCentre 5955 PS"
$DriverPath = "\\UNC_Path\To\My\Drivers"
$DriverInf = "\\UNC_Path\To\My\Drivers\x2DBRIP.inf"
$PrinterCaption = "Xerox WorkCentre 5955 PS"

$ComputerList = @()
Import-Csv "\\UNC_Path\To\Location\Where\TheCSV\Is\Stored\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
}
####################################################

$computerlist に使用する .csv ファイルにリストされている各ワークステーションで発生するエラーを次に示します。

Exception calling "Put" with "0" argument(s): "Generic failure "
At I:\PSScriptTools\Rough Network Printer for Multiple Computers Script - NOT WORKING.ps1:53 char:1
    + $Printer.Put()
    + ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

スクリプトはリストにリストされているコンピューターを識別できますが、上記のエラーが発生し、ワークステーションにプリンターが作成されません。どんな助けでも大歓迎です。

4

0 に答える 0