2016-09-07 22 views
0

我有打印机RDS 2012个问题,使用组策略来创建网络打印机 因为印刷reliablity是悲惨的2012年RDS和是一个终端服务箱网后台打印程序停止,并开始PowerShell脚本要求重新建立现有的打印机

组策略首选项是ALO有点靠不住

我想重新创建打印机使用PowerShell

Get-Printer | remove-printer get rid of them o.k 

的能力,但我要如何重新打印机。

回答

0

在PowerShell中3个或更少,您可以使用WMI,

你需要创建一个打印机IP端口(win32_tcpipPrinterPort类),添加驱动程序(Win32_PrinterDriver类),然后创建一个打印机(Win32_Printer类),

您可以使用此辅助功能,为每个任务:

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() 
} 

使用例:

创建端口:

CreatePrinterPort -PrinterIP 192.168.100.100 -PrinterPort 9100 -PrinterPortName 192.168.100.100 -ComputerName $Computer 

安装驱动程序:

InstallPrinterDriver -ComputerName $Computer -DriverName "Xerox Phaser 3600 PCL 6" -DriverPath "C:\PrinterDrivers\Xerox\x64" -DriverInf "C:\PrinterDrivers\Xerox\x64\sxk2m.inf" 

添加打印机:

CreatePrinter -PrinterCaption "Xerox Phaser 3600 PCL 6" -PrinterPortName "192.168.100.100" -DriverName "Xerox Phaser 3600 PCL 6" -ComputerName $Computer 

不用说,你需要在目标计算机上管理权限...

祝你好运

0

在将打印机安全地移除之前,在变量中提供有关它们的信息。 删除步骤后,您可以使用cmdlet添加打印机添加它们。

+0

$ lp = Get-Printer add-printer = $ lp请详细说明 – user3265817

+0

Try: '$ Printer = Get-Printer'然后: '$ Printer | %{Add-Printer -ConnectionName $ _。ComputerName}' – guiwhatsthat

相关问题