Can't remove Printer Port with Powershell

Brendan R. Jensen 1 Reputation point
2021-06-27T14:13:35.98+00:00

Can any one explain what I'm doing wrong here?

PS C:\Windows\system32> Get-PrinterPort -Name "Xerox C9000"

Name ComputerName Description PortMonitor


Xerox C9000 Standard TCP/IP Port TCPMON.DLL

PS C:\Windows\system32> Remove-PrinterPort -Name "Xerox C9000"
Remove-PrinterPort : The specified server does not exist, or the server or printer name is invalid. Names may not contain ',' or '\'
characters.
At line:1 char:1

  • Remove-PrinterPort -Name "Xerox C9000"
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (MSFT_TcpIpPrint...= "TCPMON.DLL"):ROOT/StandardCimv2/MSFT_PrinterPort) [Remove-PrinterPort], Cim
    Exception
  • FullyQualifiedErrorId : HRESULT 0x80070709,Remove-PrinterPort

I can't get PowerShell to delete this port no mater what I do! I will delete manually just fine.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,426 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 31,836 Reputation points Microsoft Vendor
    2021-06-28T03:26:33.927+00:00

    Hi,

    Please try to run the below script as Administrator.

    Restart-Service spooler  
    Get-WmiObject -Query 'Select * from MSFT_PrinterPort where name Like "Xerox C9000"' -Namespace ROOT/StandardCimv2 | Remove-WmiObject  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 31,836 Reputation points Microsoft Vendor
    2021-06-29T07:13:01.563+00:00

    Hi,

    Maybe delete the registry entry. Please try to run this as administrator.

    $path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports"  
    $name = "Xerox C9000"  
    Remove-ItemProperty -Path $path -Name $name  
    Restart-Service spooler  
    

    If it doesn't work see if the port can be removed in the GUI.

    1. Launch Control Panel\All Control Panel Items\Devices and Printers
    2. Click on any of the listed printers.
    3. Click “Printer server properties”.
    4. Click the Ports tab.
    5. Select the port and click “Delete port”.

    110069-2021-06-29-145424.png

    Also try the prnport script

    cscript $env:windir\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r "Xerox C9000"

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. Andreas 6 Reputation points
    2022-08-03T14:36:52.443+00:00

    Stumbled upon this thread having the same problem, turns out the -ComputerName parameter is a must apparently.

    Without:

    Remove-PrinterPort -Name PRN*  
    Remove-PrinterPort : Der angegebene Server ist nicht vorhanden, oder der Server- oder Druckername ist ungültig. Namen dürfen die Zeichen "," oder  
    "\" nicht enthalten.  
    In Zeile:1 Zeichen:1  
    + Remove-PrinterPort -Name PRN*  
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : NotSpecified: (MSFT_TcpIpPrint...= "TCPMON.DLL"):ROOT/StandardCimv2/MSFT_PrinterPort) [Remove-PrinterPort], CimExcep  
       tion  
        + FullyQualifiedErrorId : HRESULT 0x80070709,Remove-PrinterPort  
    

    But then..

    Remove-PrinterPort -Name PRN* -ComputerName $env:computername  
    

    .. works for me.

    Funny thing is Remove-PrinterPort -Name PRN -WhatIf* ... shows that it should work without ComputerName but well.. it is what it is.

    1 person found this answer helpful.
    0 comments No comments

  4. Brendan R. Jensen 1 Reputation point
    2021-06-28T03:30:19.72+00:00

    Sorry no luck...

    PS C:\Windows\system32> Restart-Service spooler
    WARNING: Waiting for service 'Print Spooler (spooler)' to start...

    PS C:\Windows\system32> Get-WmiObject -Query 'Select * from MSFT_PrinterPort where name Like "Xerox C9000"' -Namespace ROOT/StandardCimv2 | Remove-WmiObject
    Remove-WmiObject : Generic failure
    At line:1 char:118

    • ... Like "Xerox C9000"' -Namespace ROOT/StandardCimv2 | Remove-WmiObject
    • ~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [Remove-WmiObject], ManagementException
    • FullyQualifiedErrorId : RemoveWMIManagementException,Microsoft.PowerShell.Commands.RemoveWmiObject
    0 comments No comments

  5. Brendan Jensen 1 Reputation point
    2021-07-06T14:41:50.953+00:00

    Howdy! The point was to remove it with PowerShell so it could be automated. Still not sure why that command fails to work....

    0 comments No comments