Pregunta

I'm looking to disable the SNMP Status Enabled flag/checkbox for a printer driver using powershell. The checkbox can be found on Windows 7 under Control Panel -> Devices and Printers -> -> printer properties -> Ports -> Configure Port

Image of the checkbox desired to toggle to disable status: enter image description here

If examples of powershell scripts are available I wish to review them. I'm unable to find resources in books or online that cover this topic.

¿Fue útil?

Solución

The following works but isn't exactly elegant. It must be run from an elevated prompt. It will loop through all TCP/IP ports and disable SNMP on them if its enabled. You will need to restart (shutdown -t 0 -r) for the setting to be applied however.

    dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | gp "SNMP Enabled" | ?{$_."SNMP Enabled" -eq 1} | %{sp -Path $_.PSPath -Name "SNMP Enabled" -Value 0}

    shutdown -t 0 -r

You can also take a look at the printer cmdlets on server 2012 or use portmgr.vbs from MS.

Otros consejos

When I tried the answer, I received errors about trying to pipe into gp. Since I just wanted to turn SNMP off for each TCP/IP printer, I shortened the command to

dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | %{sp -Path $_.PSPath -Name "SNMP Enabled" -Value 0}

and then rebooted. After doing so, all my connected TCP/IP printers showed SNMP disabled in the port configuration.

Good post.

I just wanted to share that I ran the command above, along with a reboot but it didn't work 100%. I found that also changing SNMP Index to 0, in addition to the previous command and reboot did the trick. So my ps command looks as follows (I manually reboot so I don't have that in the command):

dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | %{sp -Path $_.PSPath -Name "SNMP Enabled" -Value 0}

dir "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" | %{sp -Path $_.PSPath -Name "SNMP Index" -Value 0}

This post just adds to the good work done by Michael, Bob, and Kevin and combines them into one. It'll also save a copy of the existing settings before it makes changes in case you need to revert back later on.

Also, there is no need to reboot the server - restarting the spooler service is enough:

Get-ChildItem -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports' | Out-File -FilePath 'PrinterPortSettings.txt'

Get-ChildItem -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports' | ForEach-Object -Process {
    Set-ItemProperty -Path $_.PSPath -Name 'SNMP Enabled' -Value 0
    Set-ItemProperty -Path $_.PSPath -Name 'SNMP Index' -Value 0
}

Get-Service -Name 'Spooler' | Restart-Service -Force
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top