SQL SERVER – Script – Turn off Firewall Remotely (PowerShell, NetSh, PsExec)

SQL SERVER - Script - Turn off Firewall Remotely (PowerShell, NetSh, PsExec) firewalls I was working with a client to deploy an automated solution to install SQL Server. Since this involved scripting and running PowerShell remotely, we wanted to disable the firewall. Due to automation, we were not supposed to log in to the server and use UI. So, I search on the internet and found a few ways to do that. In this blog, I am going to share scripts which can turn off the firewall remotely.


As you can imagine, there could be various methods to do this. Based on your choice, you can use any of the following methods.

1.       Command prompt:

netsh -r RemoteComputerName -u Username -p Password -c advfirewall set allprofiles state off

2.       PowerShell:

Invoke-Command -ComputerName RemoteComputerName -ScriptBlock {Set-NetFirewallProfile -Profile Public,Private,Domain -Enabled False}

3.       PSExec:

To use this method, we need to download a tool from Microsoft site called as PsExec. Here is the link to download it.

psexec \\RemoteComputerName -u UserName -p Password netsh advfirewall set allprofiles state off

You can choose based on what scripting method you are using.

NOTE: above command will turn off the firewall for ALL profiles (i.e. Private Network, Domain Network and Public Network). If you are not OK with them then choose a proper profile (privateprofile, domainprofile or publicprofile)

Let me know if you know any other way to configure

Reference: Pinal Dave (https://blog.SQLAuthority.com)

Computer Network, Powershell, SQL Scripts, SQL Server, SQL Server Security
Previous Post
SQL SERVER – How to Generate Random Password? – Enhanced Version
Next Post
SQL SERVER – ERROR: Failed to verify the Authenticode signature of FileName

Related Posts

Leave a Reply