2011-03-31 2 views
3

스크립트를 만드는 데 큰 어려움을 겪고 있습니다. 프린터를 성공적으로 만들기 위해 노력하고 있습니다. 지금까지 프린터 포트를 성공적으로 만들 수 있었지만 프린터 생성시 항상 오류가있었습니다.프린터 Powershell 만들기

은 다음과 같습니다로부터 정보를 따기입니다 CSV 파일 :

:

Exception calling "Put" with "0" argument(s): "Generic failure " 
At C:\myversion.ps1:53 char:19 
+ $objNewPrinter.Put <<<<() 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : DotNetMethodException 

내가 사용하고 코드는 이것이다 :

PrinterName,PrinterPort,IPAddress,Location,Comment,PrintDriver, 
Testprint1,Testport1,10.10.10.10,IT_Test,Test_1,HP LaserJet 4200 PCL 5e, 

내가 오류 메시지가 이것이다

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 
} 

일반 실패의 원인에 대한 의견이 있거나 문제 해결 방법에 대해 의견이있는 사람이 있습니까? 땡?

답변

0

Tim, 잘못된 매개 변수가 WMI 메서드에 전달 될 때 오류가 발생하므로 두 개의 조언이 먼저 Testport1이 아닌 실제 포트 이름을 사용하고 DriverName이 기존 드라이버의 정확한 이름이어야합니다.

+0

기존 프린터 드라이버의 정확한 이름을 나열하는 방법이 있습니까? 지금까지 나는 Printer Control Panel 애플릿의 Server Properties 섹션에서 Driver 탭을 사용 해왔다. 우리가 사용하게 될 실제 프린터 이름에 대한 테스트도 수행 할 것입니다. –

+0

'$ Class = "win32_printer" Get-WmiObject -class $ 클래스 | ft 이름, drivername -auto' – RRUZ