共用方式為


Use PowerShell in Windows 8 to Remove Printers

Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell 3.0 in Windows 8 to remove printers.
Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I have been talking to various people from the Charlotte Windows PowerShell User Group all week about doing another Windows PowerShell Saturday. It is an awful lot of work, but I think we are going to do this again. The Windows PowerShell Saturday in Charlotte sold out within a few days, and there have been many positive comments about the event. That means that people found it to be a valuable experience. So we will have another Windows PowerShell Saturday. (By the way, if you want to have one where you live, let us know via scripter@microsoft.com .)
To remove a printer with Windows PowerShell, I use the Remove-Printer function from the PrinterManagement module. There are two ways to use the Remove-Printer function:
Remove-Printer [-Name] <String> [-AsJob [<SwitchParameter>]] [-CimSession
<CimSession>] [-ComputerName <String>] [-PassThru [<SwitchParameter>]]
[-ThrottleLimit <Int32>] [-Confirm [<SwitchParameter>]] [-WhatIf
[<SwitchParameter>]] [<CommonParameters>]

Remove-Printer [-AsJob [<SwitchParameter>]] [-CimSession <CimSession>]
[-PassThru [<SwitchParameter>]] [-ThrottleLimit <Int32>] -InputObject
<CimInstance> [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
[<CommonParameters>]
What this means is that if I type the exact printer name, I can use the Remove-Printer function directly. It also tells me that I can pipe a printer object to the function. By pipelining a printer object, I can use wildcard characters.
Begin with Get-Printer
I usually begin things by using a Get type of command. So the first thing I do is use the Get-Printer function to see what printers are defined. The command is shown here:
Get-Printer
The command and its associated output are shown here:

I can use a wildcard character to avoid typing a complete printer name as shown here:
PS C:\> Get-Printer | where name -Like "my*"

Name ComputerName Type DriverName
---- ------------ ---- ----------
myotherlaser Local Brother Laser Leg Typ...
Or, I can type the exact printer name and supply it directly to the –Name parameter as shown here:
PS C:\> Get-Printer -Name myotherlaser

Name ComputerName Type DriverName...(read more)