Skip to content

Instantly share code, notes, and snippets.

@tomtorggler
Last active February 17, 2016 08:16
Show Gist options
  • Save tomtorggler/64bf5b6c92313b8d7815 to your computer and use it in GitHub Desktop.
Save tomtorggler/64bf5b6c92313b8d7815 to your computer and use it in GitHub Desktop.
Create NetFirewall Rules for SQL Server and SQL Browser executables
# get SQL services and path to executable
$services = Get-CimInstance -query 'select * from win32_service where name="sqlbrowser" or name="mssqlserver"'
# Create Firewall Rule for each of the services executables
# use splatting for better readability
foreach ($service in $services) {
$params = @{
DisplayName = $service.Name;
Action = "Allow";
Description ="Allow $($service.name)";
Enabled = 1;
Profile = "Any";
Program = $service.pathname.replace('"','')
}
New-NetFirewallRule @params
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment