我有打印機RDS 2012個問題,使用組策略來創建網絡打印機 因爲印刷reliablity是悲慘的2012年RDS和是一個終端服務箱網後臺打印程序停止,並開始PowerShell腳本要求重新建立現有的打印機
組策略首選項是ALO有點靠不住
我想重新創建打印機使用PowerShell
Get-Printer | remove-printer get rid of them o.k
的能力,但我要如何重新打印機。
我有打印機RDS 2012個問題,使用組策略來創建網絡打印機 因爲印刷reliablity是悲慘的2012年RDS和是一個終端服務箱網後臺打印程序停止,並開始PowerShell腳本要求重新建立現有的打印機
組策略首選項是ALO有點靠不住
我想重新創建打印機使用PowerShell
Get-Printer | remove-printer get rid of them o.k
的能力,但我要如何重新打印機。
在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
不用說,你需要在目標計算機上管理權限...
祝你好運
在將打印機安全地移除之前,在變量中提供有關它們的信息。 刪除步驟後,您可以使用cmdlet添加打印機添加它們。
$ lp = Get-Printer add-printer = $ lp請詳細說明 – user3265817
Try: '$ Printer = Get-Printer'然後: '$ Printer | %{Add-Printer -ConnectionName $ _。ComputerName}' – guiwhatsthat