You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 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 serverfunctionGet-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=$ServerNameProfile=$_.NameEnabled=$_.Enabled
}
}
} else {
[PSCustomObject]@{
Server=$ServerNameProfile="N/A"Enabled="Unable to Connect"
}
}
}
# Loop through each server and check the firewall status$firewallStatuses=foreach ($serverin$servers) {
Get-FirewallStatus-ServerName $server
}
# Display the results$firewallStatuses|Format-Table-AutoSize`</details>
The text was updated successfully, but these errors were encountered: