Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerate Firewall rules with PowerShell #102

Open
1 of 2 tasks
asktechsupport opened this issue Aug 15, 2024 · 1 comment
Open
1 of 2 tasks

Enumerate Firewall rules with PowerShell #102

asktechsupport opened this issue Aug 15, 2024 · 1 comment

Comments

@asktechsupport
Copy link
Owner

  • Scripted
  • Tested
@asktechsupport
Copy link
Owner Author

# Import Active Directory module`
Import-Module ActiveDirectory
# Retrieve the list of servers from Active Directory
$servers = Get-ADComputer -Filter 'OperatingSystem -like "*Windows Server*"' -Property Name | Select-Object -ExpandProperty Name
# Function to check firewall status on a server
function Get-FirewallStatus {
   param(
       [string]$ServerName
   )
   $firewallProfiles = Invoke-Command -ComputerName $ServerName -ScriptBlock {
       Get-NetFirewallProfile | Select-Object Name, Enabled
   } -ErrorAction SilentlyContinue
   if ($firewallProfiles) {
       $firewallProfiles | ForEach-Object {
           [PSCustomObject]@{
               Server   = $ServerName
               Profile  = $_.Name
               Enabled  = $_.Enabled
           }
       }
   } else {
       [PSCustomObject]@{
           Server   = $ServerName
           Profile  = "N/A"
           Enabled  = "Unable to Connect"
       }
   }
}
# Loop through each server and check the firewall status
$firewallStatuses = foreach ($server in $servers) {
   Get-FirewallStatus -ServerName $server
}
# Display the results
$firewallStatuses | Format-Table -AutoSize`

</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant