murano-repository/muranorepository/Services/scripts/Alter-FirewallRulesForSQL.ps1
Ekaterina Fedorova d7769d4927 Restore Services folder after unsuccessful move
Change-Id: If95e9c1b66bd64c1989243bc1590b332dc3c9e20
2013-11-13 11:23:02 +00:00

62 lines
1.3 KiB
PowerShell

trap {
&$TrapHandler
}
$FW_Rules = @{
"SQL Server Data Connection" = "1433";
"SQL Admin Connection" = "1434";
"SQL Service Broker" = "4022";
"SQL Debugger/RPC"="135";
}
$FW_Proto = "TCP"
function Add-NetshFirewallRule {
param (
[HashTable] $hshRules,
[String] $proto
)
foreach ($h in $hshRules.GetEnumerator()) {
try {
$command="advfirewall firewall add rule name=`"$($h.Name)`" dir=in action=allow protocol=$proto localport=$($h.Value)"
Start-Process -FilePath netsh -ArgumentList $command -Wait
}
catch {
$except= $_ | Out-String
Write-LogError "Add rule $($h.Name) FAILS with $except"
}
}
}
function Remove-NetShFirewallRule {
param (
[HashTable] $hshRules
)
foreach ($h in $hshRules.GetEnumerator()) {
try {
$command="advfirewall firewall delete rule name=`"$($h.Name)`""
Start-Process -FilePath netsh -ArgumentList $command -Wait
}
catch {
$except= $_ | Out-String
Write-LogError "Delete rule $($h.Name) FAILS with $except"
}
}
}
function Enable-SQLExternalAccess {
Add-NetshFirewallRule $FW_Rules $FW_Proto
}
function Disable-SQLExternalAccess {
Remove-NetshFirewallRule $FW_Rules $FW_Proto
}