I know I posted something like the following in another Topic quite a while ago, but I recently did some more work on the Powershell script that eases setup of multi-terminal systems.
I went through this again just yesterday when I discovered that my custom Firewall Rules somehow went missing (I have a sneaking suspicion Win 10 updated deleted them, but cannot find any evidence of this happening when searching on the 'net).
##Create a BAT file:
fwrules.bat
D:
CD D:\Programs
powershell -executionpolicy bypass -File fwrules.ps1
pause
Make changes to the BAT file as necessary. You want to ensure that you navigate to the path where the BAT file and the PS1 file reside on your system. In my case, the files were in D:\Programs\
, so the first 2 lines make that happen.
##Create a PS1 file:
fwrules.ps1
function getRule {
param(
[string] $name
)
$fw = Get-NetFirewallRule -DisplayName "$name" -ErrorAction:SilentlyContinue
if ($fw) {
return [bool]$true
} else {
return [bool]$false
}
}
function setRule {
param(
[string] $name,
[string] $port,
[string] $protocol,
[string] $profile
)
Set-NetFirewallRule -DisplayName "$name" -Action "Allow" -Direction "Inbound" -Enabled "True" -LocalPort "$port" -Profile "$profile" -Protocol "$protocol" -Verbose
}
function addRule {
param(
[string] $group,
[string] $name,
[string] $port,
[string] $protocol,
[string] $profile
)
$fw = getRule("$name")
if ($fw) {
Write-Host -ForegroundColor:Black -BackgroundColor:Magenta "`r`n*** Rule already exists, Modifying Rule: '$name' ..."
setRule -name:"$name" -port:"$port" -profile:"$profile" -protocol:"$protocol" -Action "Allow" -Direction "Inbound" -Enabled "True"
} else {
Write-Host -ForegroundColor:Black -BackgroundColor:Green "`r`n****** Adding Rule: '$name' ..."
New-NetFirewallRule -Group "$group" -DisplayName "$name" -Action "Allow" -Direction "Inbound" -Enabled "True" -LocalPort "$port" -Profile "$profile" -Protocol "$protocol"
}
}
#
# This is where you specify the addition of Firewall Rules
#
addRule -profile:"Private" -protocol:"TCP" -port:1433 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS SQL Traffic"
addRule -profile:"Private" -protocol:"UDP" -port:1434 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS SQL Browser Traffic"
addRule -profile:"Private" -protocol:"TCP" -port:9000 -group:"Custom Rule - SambaPOS Multi-terminal" -name:"SambaPOS Messaging Server"
The last 3 lines in the PS1 file are the important lines. They use the preceding functions. Modify them as necessary if your system is configured differently. For example, your Ports might be different, or maybe you want the Rule to have a Profile of “All” or “Public”. The Profile used depends on the Network Connection Type.
On the Server where the Message Service is running, and the DB is running, right-click the BAT file, and choose Run as Administrator. To show what it looks like, I deleted 1 of the above Rules (the one named “SambaPOS SQL Browser Traffic”), so this output shows that it is updating 2 Rules (magenta), and adding 1 Rule (green) …