我正在尝试制作一个PowerShell程序来删除打印机。程序首先提示打印机。我不能让打印机单独显示它们都显示为一个选项。
$installedprinters = Get-WMIObject -Class Win32_Printer | Select -
ExpandProperty Name | ft -HideTableHeaders | Out-String
Write-Host $installedprinters
ForEach($name in ($installedprinters))
{[void] $objListBox.Items.Add($printer)}
答案 0 :(得分:0)
虽然您的代码不满足Minimal, Complete, and Verifiable example规则,但下一个代码段可以提供帮助:
$installedprinters = Get-WMIObject -Class Win32_Printer
ForEach ( $printer in $installedprinters ) {
Write-Host ( $printer.Name )
[void] $objListBox.Items.Add( $printer.Name )
}