Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Writing an improved Firewall Rule retrieval script

$
0
0

So, I've been looking at attempting to improve the firewall rule retrieval script that I use when performing system audits.

So far, I have the following:

Function Get-FWdump {
    $Output = @(netsh advfirewall firewall show rule name=all dir=in)
    $Object = New-Object -Type PSObject
    $Output | Where {$_ -match '^([^:]+):\s*(\S.*)$' } | Foreach {
        [int]$ParseResult = 0
        if ([int]::TryParse($Matches[2], [ref]$ParseResult))
        {
            $Value = $ParseResult
       }
        else
        {
            $Value = $Matches[2]
        }
        $Name = $Matches[1] -replace ' '
        $Object | Add-Member -Type NoteProperty -Name $Name -Value $Value
        
    }
    Write-Output $Object
}
Get-FWdump | Format-Table -AutoSize

The problem that I am encountering is this: I get a whole bunch of "Add-Member : Cannot add a member with the name "NNN" because a member with that name already exists. If you want to overwrite the member anyway, use the Force parameter to overwrite it."

I understand the error, but I'm having trouble coming up with a good way to fix it.


Viewing all articles
Browse latest Browse all 8583

Trending Articles