$oldErrorActionPreference = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' Get-Printer -Name 'LaserJet Marketing' | Remove-Printer # Check if removal succeeded if ( Get-Printer -Name 'LaserJet marketing' ) { Write-Host "Failed to remove 'LaserJet Marketing' printer" } $ErrorActionPreference = $oldErrorActionPreference