PowerShell to enable or disable sharing on Printers

This article assumes that the print queues are already setup. The cmdlet is included in Windows 2012 R2 OS by default but can be used to enable/disable printer share on previous versions of Windows remotely.

To share a printer
Set-Printer -Name DummyPrinter -Shared $True -Published $True -ShareName MyDummyPrinter

To share a printer on remote computer
Set-Printer -Name DummyPrinter -Shared $True -Published $True -ShareName MyDummyPrinter -ComputerName PrintSvr01

Where,
DummyPrinter is the name of the print queue,
MyDummyPrinter is the desired shared name and
PrintSvr01 is the remote server that hosts the printer.
Please note, the parameter -Publish enabled the option ‘List in Directory’. You can omit if you do not want the option.

Multiple Printers?
get-printer -ComputerName PrintSvr01 | foreach{Set-Printer -name $_.name -Shared $true -ShareName $_.name -Published $true -ComputerName PrintSvr01}

To unshare a printer
To unshare, set the –Shared parameter to $False
Set-Printer -Name DummyPrinter -Shared $True -ComuterName PrintSvr01