Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active March 13, 2018 00:27
Show Gist options
  • Save Jaykul/2c121e4f99618d81276c1787fca605f0 to your computer and use it in GitHub Desktop.
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).
#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