Get-NetFirewallRule | Where-Object {$_.enabled -eq "true" -and $_.direction -eq "inbound"} |
ForEAch-Object{
$Rule = $_
$_ | Get-NetFirewallPortFilter |
ForEach-Object{
[pscustomobject]@{
Rule = $Rule.DisplayName
Profile= $Rule.Profile
Enabled= $_.Enabled
Protocol = $_.Protocol
LocalPort = $_.LocalPort
RenmotePort = $_.RemotePort
}
}
} | export-csv ./test.txt -encoding default
PS C:\Windows\System32> New-NetFirewallRule -DisplayName "TEST4" -Profile Private,Domain -Direction Outbound -Protocol TCP -LocalPort 443,1-4 -LocalAddress 192.168.1.1-192.168.1.6,192.168.0.3,192.168.2.0/24 -Action Allow -Enabled false -Group aaaaa -Description descri -OverrideBlockRules $false
PS C:\Windows\System32> New-NetFirewallRule -DisplayName "TEST3" -Profile Private,Domain -Direction Outbound -Protocol TCP,UDP -LocalPort 443 -LocalAddress 192.168.1.1-192.168.1.6,192.168.0.3,192.168.2.0/24 -Action Allow -Enabled false
New-NetFirewallRule: Cannot process argument transformation on parameter 'Protocol'. Cannot convert value to type System.String.
D:\Temp\input.csv
Name,Profile,Direction,LocalPort
1,"1","1,1"
2,"2","2,2"
"TEST4","Private,Domain","Outbound","443,1-4"
$i=1
import-csv D:\Temp\input.csv | foreach {
Write-Host $i : $_.Name , $_.Profile
$i++
}