![以编程方式将 32 位打印机驱动程序添加到 64 位 Windows 服务器](https://linux22.com/image/673133/%E4%BB%A5%E7%BC%96%E7%A8%8B%E6%96%B9%E5%BC%8F%E5%B0%86%2032%20%E4%BD%8D%E6%89%93%E5%8D%B0%E6%9C%BA%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F%E6%B7%BB%E5%8A%A0%E5%88%B0%2064%20%E4%BD%8D%20Windows%20%E6%9C%8D%E5%8A%A1%E5%99%A8.png)
目标:在 Windows 2012 R2 打印服务器上自动安装打印机的 x64 和 x32 驱动程序。
信息:到目前为止,我已经能够毫无问题地安装 x64 打印驱动程序。我在现有打印机上安装 x32 的尝试如下:
# - Set the driver name
$driverName = "HP Universal Printing PCL 6"
# - Get a list of printers that already have x64 drivers installed
$printers = get-Printer | where {$_.drivername -eq $driverName}
Foreach ($printer in $printers) {
# - This is the only way I could think to get the x32 print driver. It is already installed on the system with pnputil
$driver32 = get-printerdriver | where {$_.name -eq $driverName -and $_.printerenvironment -eq "Windows NT x86"}
# -- Turn off the share so we can add the driver.
$sharename = get-printer -name $printer | select -expand ShareName
set-printer -name $printer -Shared $false -confirm:$false
# -- This does not work. The set-printer cmdlet does not accept pipeline input.
$driver32 | set-printer -name $printer -confirm:$false
# -- Re-share the printer.
set-printer -name $printer -Shared $true -Sharename $sharename
}
问题:由于 Set-Printer 不接受管道输入,我想不出其他方法来告诉它要安装哪个驱动程序。x32 和 x64 驱动程序名称相同,所以我不知道如何使用 -DriverName 参数进行区分。