很抱歉向大家询问,但需要一些帮助才能得到这个。我在许多计算机上安装了一些打印机,例如 \server\printer。我想用 powershell 脚本删除它们,但无法完成。我在想这样的事情:
$printers=Get-Printer | where { $_.Type -eq 'Connection'} | select name /* this part show me only \\server\printers */
$printers | ForEach-Object {
if ($printers) {
Remove-Printer -Name $printers -Confirm:$false
}
}
提前感谢大家。
这是因为您向Remove-Printer cmdlet 提供了完整的打印机列表。您必须一次提供一台打印机。
您在 foreach 循环内,可以使用
$PSItem
或 短别名来获取当前打印机$_
。$PSItem
(and$_
) 表示“ForEach 循环中的当前对象”这应该有效: