Netsh Disable Policy based on Port Numbers

Hi All,

I am trying to create a powershell script (Target Level OS 2008 R2) that 1. Runs through a array of ports 2. List all firewall policy associated with the ports 3. Capture the “Rule Names” into a array 4. Run through each “Rule Nmae”, either disable or enable the policy based on current state.

Current Code

$array = @("3050", "300", "8080","7080","5090") for ($i=0; $i -lt $array.length; $i++){ $searchPort="(LocalPort.*" + $array[$i] + ")" $front = netsh advfirewall firewall show rule dir=in name=all | select-string -pattern ($searchPort) -context 9,4 Write-Host $front } 

Copy of Result based on my current script:

Rule Name: interbase port ---------------------------------------------------------------------- Enabled: Yes Direction: In Profiles: Domain,Private,Public Grouping: LocalIP: Any RemoteIP: Any Protocol: TCP LocalPort: 3050 RemotePort: Any Edge traversal: No Action: Allow Rule Name: MT ---------------------------------------------------------------------- Enabled: Yes Direction: In Profiles: Domain,Private,Public Grouping: LocalIP: Any RemoteIP: Any Protocol: UDP LocalPort: 300 RemotePort: Any Edge traversal: No Action: Allow Rule Name: medtech port ---------------------------------------------------------------------- Enabled: Yes Direction: In Profiles: Domain,Private,Public Grouping: LocalIP: Any RemoteIP: Any Protocol: UDP LocalPort: 300 RemotePort: Any Edge traversal: No Action: Allow 

I am stuck at Point 3 as per my list above. Is anyone able to help or possibly direct me in the correct direction?

Thank you in advance.

submitted by /u/wunderlust88
[link] [comments]

Leave a Reply