1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fix: fw rule names must always be quoted, to permit spaces ' ' and brackets '()'

Without this fix, the 'netsh' command gets name=Firewall Rule Name instead of name="Firewall Rule Name". Thus causing all sorts of havoc. Basic shell quoting rules seems to apply to Windows Powershell too. This is very much needed as many of windows 10's default firewall rules contain spaces and brackets () characters.
This commit is contained in:
Dreamcat4 2015-10-05 21:10:59 +01:00 committed by Matt Clay
parent 1d09eaf6d0
commit b9dd3568f3

View file

@ -24,7 +24,7 @@ function getFirewallRule ($fwsettings) {
try { try {
#$output = Get-NetFirewallRule -name $($fwsettings.name); #$output = Get-NetFirewallRule -name $($fwsettings.name);
$rawoutput=@(netsh advfirewall firewall show rule name=$($fwsettings.Name)) $rawoutput=@(netsh advfirewall firewall show rule name="$($fwsettings.Name)")
if (!($rawoutput -eq 'No rules match the specified criteria.')){ if (!($rawoutput -eq 'No rules match the specified criteria.')){
$rawoutput | Where {$_ -match '^([^:]+):\s*(\S.*)$'} | Foreach -Begin { $rawoutput | Where {$_ -match '^([^:]+):\s*(\S.*)$'} | Foreach -Begin {
$FirstRun = $true; $FirstRun = $true;
@ -123,8 +123,9 @@ function createFireWallRule ($fwsettings) {
$execString+=" "; $execString+=" ";
$execString+=$key; $execString+=$key;
$execString+="="; $execString+="=";
$execString+='"';
$execString+=$fwsetting.value; $execString+=$fwsetting.value;
#$execString+="'"; $execString+='"';
}; };
try { try {
#$msg+=@($execString); #$msg+=@($execString);
@ -152,7 +153,7 @@ function createFireWallRule ($fwsettings) {
function removeFireWallRule ($fwsettings) { function removeFireWallRule ($fwsettings) {
$msg=@() $msg=@()
try { try {
$rawoutput=@(netsh advfirewall firewall delete rule name=$($fwsettings.name)) $rawoutput=@(netsh advfirewall firewall delete rule name="$($fwsettings.name)")
$rawoutput | Where {$_ -match '^([^:]+):\s*(\S.*)$'} | Foreach -Begin { $rawoutput | Where {$_ -match '^([^:]+):\s*(\S.*)$'} | Foreach -Begin {
$FirstRun = $true; $FirstRun = $true;
$HashProps = @{}; $HashProps = @{};