列出所有使用Powershell的打印机

我遇到的问题列出了使用Powershell的计算机上的所有打印机。

我们有一个批处理脚本,使用PrintUI添加/删除/列出“每台计算机”打印机。

我可以使用PrintUI列出打印机。

rundll32 printui.dll,PrintUIEntry /ge /c"%UNC-NAME%" 

这将列出每个电脑打印机,而…

  Get-WMIObject -Class Win32_Printer -ComputerName $ComputerName 

将列出WMI中的所有打印机。

在上面的例子中,我有一个有3台打印机的系统,当用户login的时候,WMI看到其中的2个,PrintUI看到的是1。

我很惊讶我怎么能列出他们! 这样我可以脚本审计/添加/删除“每台计算机”和“本地”打印机

共享打印机

 Get-Printer -ComputerName pc| where Shared -eq $true | fl Name 

得不到共享打印机

  Get-Printer -ComputerName pc | where Shared -eq $false | fl Name 

获得映射打印机

 Get-WMIObject Win32_Printer -ComputerName $env:COMPUTERNAME | where{$_.Name -like “*\\*”} | select sharename,name 

得到所有的打印机

 Get-WMIObject Win32_Printer -ComputerName $env:COMPUTERNAME