#Enable File And Printer Sharing In Windows 10 Without Using The netsh Command in PowerShell
#It is as simple as enabling the pre-configured rule in Windows Firewall to enable File and Printer Sharing in Windows 10 but using netsh
is the old fashion way.
#Run this command in an elevated PowerShell prompt and you are done.
Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a
#The Long Story…
#Allow File and Printer Sharing services through the Windows Firewall to access shared information and to share information of your own. These commands all work in both in PowerShell and PowerShell Direct.
#Get Firewall rules for File and Printer Sharing
#This command shows the individual rules and the network connection profiles that are explicitly enabled and disabled for the File and Printer Sharing
services.
Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|select Name,DisplayName,Enabled,Profile|ft -a
#Enable File and Printer Sharing for Private and Domain network profiles
#Enable the File and Printer Sharing
services for the Private
and Domain
network connection profiles by applying the preconfigured Windows Firewall group rule called File and Printer Sharing
by typing this:
Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Profile 'Private, Domain' -Enabled true -PassThru|select Name,DisplayName,Enabled,Profile|ft -a
#▲That is what it looks like under Advanced Sharing Settings
when the File and Printer Sharing
firewall rule is enabled.
#Set Network Connection Profile to Private
.
#I set the variable $InterfaceAlias
to automatically query my primary network interface or NIC. The -NlMtuBytes 1500
switch is what makes it work. If you have changed the Maximum Transmission Unit (MTU) from the defaults then this command will need to be modified:
$InterfaceAlias = (Get-NetIPInterface -AddressFamily IPv4 -ConnectionState Connected -NlMtuBytes 1500 -Verbose) #this works for me to automatically identify my nic - mtu 1500 may vary Set-NetConnectionProfile -InterfaceIndex $InterfaceAlias.ifIndex -Ne
#Disable File and Printer Sharing on all network profiles
Get-NetFirewallRule -DisplayGroup 'File and Printer Sharing'|Set-NetFirewallRule -Enabled false -PassThru|select Name,DisplayName,Enabled,Profile|ft -a
#▲It will look like this when File and Printer Sharing
is disabled.