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

  • Question

  • 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.





    • Edited by Vladimir Amir Wednesday, August 24, 2016 9:49 AM minor corrections
    Wednesday, August 24, 2016 9:32 AM

Answers

  • 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

    Wednesday, August 24, 2016 10:00 AM
  • 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 tnmff@microsoft.com.

    Thursday, August 25, 2016 12:22 PM
    Owner
  • 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


    Thursday, August 25, 2016 1:24 PM

All replies

  • 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

    Wednesday, August 24, 2016 10:00 AM
  • 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 tnmff@microsoft.com.

    Thursday, August 25, 2016 12:22 PM
    Owner
  • 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


    Thursday, August 25, 2016 1:24 PM