Converting the Windows Script Host RemovePrinterConnection Method
Definition: Removes a shared network printer connection from your computer system.
You can use WMI (and the Get-WMIObject cmdlet) to delete printers from your computer. (Don’t let the official WSH definition throw you off here: in WSH, as in PowerShell, you can remove local printer connections as well as network printer connections.) How do you remove a printer connection using Windows PowerShell? Why, like this, of course:
$a = Get-WMIObject -query "Select * From Win32_Printer Where Name = 'Test Printer'" $a.delete()
As you can see, in line 1 we use Get-WMIObject and the –query parameter to retrieve a specific printer from the local computer; in particular, we want the printer that has a Name equal to Test Printer. After we have this printer in tow we simply use the Delete method to remove that printer from the computer.
Note. Yes, we know: in VBScript the method is named Delete_, with an underscore following the word Delete. Why the difference in method names between PowerShell and VBScript? In a nutshell, that’s because they use different objects. When working with the Get-WMIObject PowerShell goes through the .NET Framework, and returns an instance of the System.Management.ManagementObject class; in that class, the method is named Delete. VBScript, meanwhile, uses the WMI Scripting API and returns an instance of the SWbemObject class; with that class the method is named Delete_.
As to why the two classes use two different method names, well, your guess as good as ours.