Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
#poszukujemy jakie są insancje i gdzie jest SqLserwer.exe
Get-CimInstance Win32_Service |
Where-Object {
$_.Name -like „MSSQL*” -and $_.PathName -match „sqlservr.exe”
} |
ForEach-Object {
$exe = [regex]::Match($_.PathName,’^”?(.*?)”?(?=\s-|$)’).Groups[1].Value
if (Test-Path $exe)
{
New-NetFirewallRule `
-DisplayName „SQL Server plik_exe- $($_.Name)” `
-Direction Inbound `
-Program $exe `
-Action Allow `
-Profile Domain,Private `
-ErrorAction SilentlyContinue
Write-Host „Dodano regułę dla $($_.Name)”
}
}
#Enabling SQL Server Ports
New-NetFirewallRule -DisplayName “SQL Server” -Direction Inbound –Protocol TCP –LocalPort 1433 -Action allow
New-NetFirewallRule -DisplayName “SQL Admin Connection” -Direction Inbound –Protocol TCP –LocalPort 1434 -Action allow
New-NetFirewallRule -DisplayName “SQL Database Management” -Direction Inbound –Protocol UDP –LocalPort 1434 -Action allow
New-NetFirewallRule -DisplayName “SQL Service Broker” -Direction Inbound –Protocol TCP –LocalPort 4022 -Action allow
New-NetFirewallRule -DisplayName “SQL Debugger/RPC” -Direction Inbound –Protocol TCP –LocalPort 135 -Action allow
#Enabling SQL Analysis Ports
New-NetFirewallRule -DisplayName “SQL Analysis Services” -Direction Inbound –Protocol TCP –LocalPort 2383 -Action allow
New-NetFirewallRule -DisplayName “SQL Browser” -Direction Inbound –Protocol TCP –LocalPort 2382 -Action allow
#Enabling Misc. Applications
New-NetFirewallRule -DisplayName “HTTP” -Direction Inbound –Protocol TCP –LocalPort 80 -Action allow
New-NetFirewallRule -DisplayName “SSL” -Direction Inbound –Protocol TCP –LocalPort 443 -Action allow
New-NetFirewallRule -DisplayName “SQL Server Browse Button Service” -Direction Inbound –Protocol UDP –LocalPort 1433 -Action allow
#Enable Windows Firewall
Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow -NotifyOnListen True -AllowUnicastResponseToMulticast True
New-NetFirewallRule `
-DisplayName „SQL Server Program” `
-Direction Inbound `
-Program „C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Binn\sqlservr.exe” `
-Action Allow `
-Profile Private
———-DIAGNOZA
Get-NetFirewallRule -DisplayName "SQL Server" | Get-NetFirewallProfile
Get-NetFirewallRule -DisplayName "SQL Server" | Format-List *
9.
Sprawdź, co blokuje Firewall
Możesz włączyć logowanie:
Set-NetFirewallProfile `
-LogBlocked True `
md=c:\!!!! LOG !!!
-LogFileName ":\!!!! LOG !!!\pfirewall.log"
0 Comments