首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式更新网络打印机驱动程序

以编程方式更新网络打印机驱动程序
EN

Stack Overflow用户
提问于 2013-11-26 20:40:01
回答 1查看 2.4K关注 0票数 0

这是一个我希望用一些简单的Powershell解决的部署问题:

当执行32位Windows到64位Windows 7迁移时,USMT正在迁移所有的网络打印机,这是很棒的。但是,由于驱动程序显然不正确,所以需要手动升级驱动程序(右击打印机->更新驱动程序)。 此操作是否有WMI函数或Powershell cmdlet?我似乎找不到任何关于它的文件!由于我们的USMT任务序列与部署是分开的,并且运行在迁移用户的上下文中,所以我确信它会工作。如果我能得到正确的语法,在TS的末尾添加一个Powershell脚本,这将是完美的。

我基本上是在寻找与右键单击打印机并单击“更新驱动程序”相同结果的函数。我已经交叉张贴在这里从MDT论坛,因为我认为这可能是更合适的!

我看过Win32_Printer类,但它似乎没有我所需要的东西。

EN

回答 1

Stack Overflow用户

发布于 2013-11-27 01:21:01

根据我的理解,执行RC->更新驱动程序并不是管理打印驱动程序的正确方法。

Update驱动程序旨在将驱动程序从X版本更新到下一个版本Y,而不是真正正确地将驱动程序从Win XP驱动程序更改为Win 7驱动程序(即,如果XP驱动程序位于1.0版本,而Win 7驱动程序位于1.0,则运行update驱动程序将不会执行任何操作,因为版本相同)。

第一个也是最好的选择是使用PowerShell删除打印机,然后重新添加它们(然后安装Windows7驱动程序)。这样你就能保证他们能发挥作用。

脚本将如下所示:

代码语言:javascript
复制
#Get list of all the printers on the machine
$printers = gwmi win32_printer

#Save default Printer
$DefaultPrinter = $printers | where{$_.Default} | Select ShareName

#Create a list of all the printers we want to delete (in this case I am deleting all network printers)
$PrintersToDelete = $printers | where{$_.Network -eq $true} 

#Create a list of all the printers we want to add (in this case, all network printers I just deleted)
$PrintersToAdd = $printers | where{$_.Network -eq $true} | Select Name

#Delete the printers I want to delete
$PrintersToDelete | foreach{$_.delete()}

#Add back all printers we want to add
$PrintersToAdd | foreach{(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($_.Name)}

#Get list of all the new printers on the machine
$printers = gwmi win32_printer

#Set the default printer
$NewDefaultPrinter = $printers | where{$_.DeviceID -match $DefaultPrinter}
$NewDefaultPrinter.SetDefaultPrinter()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20227505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档