Last active
March 13, 2018 00:27
-
-
Save Jaykul/2c121e4f99618d81276c1787fca605f0 to your computer and use it in GitHub Desktop.
Enable File and Printer Sharing (or any other firewall group) on the Domain profile (only).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 5.0 | |
#Requires -Module NetSecurity | |
param( | |
$DisplayGroup = "File and Printer Sharing", | |
[Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]$NetworkProfile = "Domain" | |
) | |
foreach($rule in Get-NetFirewallRule -DisplayGroup $DisplayGroup) { | |
if($NetworkProfile -ne "Any") { | |
[Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]$Other = ([int]([Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]"Private,Public,Domain") - ([Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile]$NetworkProfile)) | |
Set-NetFirewallRule -Input $rule -Profile $Other -Enabled False | |
} | |
Copy-NetFirewallRule -Input $rule -NewName ($rule.Name + " ($NetworkProfile)") -PassThru | | |
Set-NetFirewallRule -Profile $NetworkProfile -Enabled True | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment