3
在獲取我正在努力成功創建打印機的腳本時遇到很大困難。到目前爲止,我已經成功地創建了成功創建的打印機端口,但在打印機創建時它總是出錯。創建打印機Powershell
CSV文件在那裏了,從外觀採摘的信息是這樣的:
PrinterName,PrinterPort,IPAddress,Location,Comment,PrintDriver,
Testprint1,Testport1,10.10.10.10,IT_Test,Test_1,HP LaserJet 4200 PCL 5e,
該錯誤消息我得到的是這樣的:
Exception calling "Put" with "0" argument(s): "Generic failure "
At C:\myversion.ps1:53 char:19
+ $objNewPrinter.Put <<<<()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我使用的代碼是這樣的:
trap { $error[0].Exception | get-member } $objNewPrinter.Put()
Write-Host ("`tCreating " + $strPrinterName.Count + " Printer's`t")
$objPrint = [WMICLASS]"\\timvista\ROOT\cimv2:Win32_Printer"
$objPrint.psbase.scope.options.EnablePrivileges = $true
## Loop through and create each printer
For($i=0; $i -lt $PrinterName.count; $i++)
{
$objNewPrinter = $objPrint.createInstance()
$objNewPrinter.DeviceID = $PrinterName[$i] ## This is the printer name
$objNewPrinter.DriverName = $PrintDriver[$i]
$objNewPrinter.PortName = $PrinterPort[$i]
$objNewPrinter.Location = $Location[$i]
$objNewPrinter.Comment = $Comment[$i]
$objNewPrinter.ShareName = $PrinterName[$i]
$objNewPrinter.Put()
$objPrint
## Add Security group
## Not completed yet
}
有沒有人對通用故障是什麼以及如何處理故障是嗎?
有沒有辦法通過powershell列出現有打印驅動程序的確切名稱?到目前爲止,我一直使用打印機控制面板小程序的「服務器屬性」部分中的「驅動程序」選項卡。我也將對我們將使用的真實打印機名稱進行測試。 – 2011-03-31 15:19:14
'$ Class =「win32_printer」 Get-WmiObject -class $ Class | ft名稱,drivername -auto' – RRUZ 2011-03-31 15:27:54