Share via


How to switch on/off (enable/disable) a network discovery and file and printer sharing in powershell?

Question

Wednesday, August 24, 2016 9:32 AM

Hello.

How to switch on/off (enable/disable) a network discovery and file and printer sharing in powershell?

It might be that before switching on/off i need to enable a service and these are different operations; in such case i'll need this too.

I need an example of such script or a link to a right knowledge base section.

Thanks.

All replies (3)

Wednesday, August 24, 2016 10:00 AM ✅Answered | 1 vote

Hello,

Run the following command:
Get-NetConnectionProfile
See the network name you want to change its type and run the following command:
Set-NetConnectionProfile -Name <N/W name> -NetworkCategory Public

Regards, Regin Ravi


Thursday, August 25, 2016 12:22 PM ✅Answered

Hi,

Why not use the command as below?

netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=No

Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, August 25, 2016 1:24 PM ✅Answered

Here goes:

  1. Network Discovery:
    netsh advfirewall firewall set rule group=”network discovery” new enable=yes
  2. File and Printer Sharing:
    netsh firewall set service type=fileandprint mode=enable profile=all
  3. Service start/stop:
    Start-Service <service name>
    To get a list of the service names, run
    Get-Service

Note that you need to run these commands as admin.

Best regards, George