Scripts to open Windows Firewall Ports for SQL Server

I was looking for a PowerShell replacement of the script provided in MS KB “How to open the firewall port for SQL Server on Windows Server 2008” which uses the netsh command to open the Windows firewall ports for SQL Server. Because in future versions of Windows, Microsoft might remove the Netsh functionality for Windows Firewall with Advanced Security. Microsoft also recommends that you transition to Windows PowerShell if you currently use netsh to configure and manage Windows Firewall with Advanced Security. And I found the answer it on the TechNet Forums. For reference I have posted the two scripts after the read more. First the good ol’ netsh version:

The PowerShell version of the script:

The following command will check if the “Execution Policy” is set to unrestricted. If not, it will set it to unrestricted, then run the target PowerShell script. Finally, the command will set the Execution Policy back to the previous value.

Source.