简体   繁体   English

删除名称中包含“ EXAMPLE”的打印机

[英]Delete printer which contain “EXAMPLE” in their name

I am trying to build a PS script, to deletes all networkprinters which contain "EXAMPLE" in their name. 我正在尝试构建PS脚本,以删除名称中包含“ EXAMPLE”的所有网络打印机。

So far I have the following code: 到目前为止,我有以下代码:

Get–WMIObject Win32_Printer | where{$_.Network -eq ‘true‘} | foreach{$_.delete()}

But this deletes every networkprinter. 但这会删除每个网络打印机。

Since you are using Windows 7, you can still utilize WMI to delete the printers. 由于您使用的是Windows 7,因此仍然可以使用WMI删除打印机。 Otherwise the other alternatives are using methods from the .Net classes System.Printing or System.Drawing.Printing . 否则,其他替代方法将使用.Net类System.PrintingSystem.Drawing.Printing But it looks like you just need to and another filter in your where block 但是看起来您只需要在where块中添加另一个过滤器

Get–WMIObject Win32_Printer | where{($_.Network -eq 'true') -and ($_.Name -like "*EXAMPLE*") } | foreach{$_.delete()}
# First check with -WhatIf, then remove -WhatIf when you are sure the command is targetting the right printer
Get-Printer | ?{ $_.Name.Contains("EXAMPLE") -and $_.Type -eq "Connection" } | Remove-Printer -Whatif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM