<#
.SYNOPSIS
Advanced Network Configuration Analyzer
.DESCRIPTION
This script analyzes network configurations across multiple servers or workstations in a domain environment.
It provides detailed information about IP configurations, firewall rules, network adapters, DNS settings, and more.
.NOTES
File Name : AdvancedNetworkConfigAnalyzer.ps1
Author : [Your Name]
Prerequisite : PowerShell V5.1 or later, Active Directory module, and appropriate permissions
Version : 1.0
Date : [Current Date]
.EXAMPLE
.\AdvancedNetworkConfigAnalyzer.ps1
#>
# Import required modules
Import-Module ActiveDirectory
# Global variables
$global:reportPath = "$env:USERPROFILE\Desktop\Network_Config_Report_$(Get-Date -Format 'yyyyMMdd_HHmmss').html"
<#
.SYNOPSIS
Displays the main menu of the tool.
#>
function Show-Menu {
Clear-Host
Write-Host "=== Advanced Network Configuration Analyzer ===" -ForegroundColor Cyan
Write-Host "1. Analyze IP Configurations"
Write-Host "2. Examine Firewall Rules"
Write-Host "3. Inspect Network Adapters"
Write-Host "4. Check DNS Settings"
Write-Host "5. Review Network Shares"
Write-Host "6. Analyze Network Routes"
Write-Host "7. Check Remote Access Settings"
Write-Host "8. Generate Comprehensive HTML Report"
Write-Host "9. Exit"
}
<#
.SYNOPSIS
Gets a list of computers to analyze.
.OUTPUTS
Array of computer names.
#>
function Get-TargetComputers {
$option = Read-Host "Analyze (A)ll domain computers, (S)pecific computers, or (F)ile input? (A/S/F)"
switch ($option.ToUpper()) {
"A" {
return (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name)
}
"S" {
$computers = @()
do {
$computer = Read-Host "Enter computer name (or press Enter to finish)"
if ($computer -ne "") { $computers += $computer }
} while ($computer -ne "")
return $computers
}
"F" {
$filePath = Read-Host "Enter the path to the file containing computer names"
return (Get-Content $filePath)
}
default {
Write-Host "Invalid option. Defaulting to all domain computers." -ForegroundColor Yellow
return (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name)
}
}
}
<#
.SYNOPSIS
Analyzes IP configurations of target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing IP configuration details.
#>
function Analyze-IPConfigurations {
param([string[]]$Computers)
Write-Host "`nAnalyzing IP Configurations..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$ipConfig = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-NetIPConfiguration | Select-Object InterfaceAlias, IPv4Address, IPv4DefaultGateway, DNSServer
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
IPConfigurations = $ipConfig
}
}
catch {
Write-Host "Error analyzing $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Examines firewall rules on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing firewall rule details.
#>
function Examine-FirewallRules {
param([string[]]$Computers)
Write-Host "`nExamining Firewall Rules..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$firewallRules = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-NetFirewallRule | Where-Object Enabled -eq 'True' |
Select-Object Name, DisplayName, Direction, Action, Profile
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
FirewallRules = $firewallRules
}
}
catch {
Write-Host "Error examining firewall rules on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Inspects network adapters on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing network adapter details.
#>
function Inspect-NetworkAdapters {
param([string[]]$Computers)
Write-Host "`nInspecting Network Adapters..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$adapters = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed, MacAddress
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
NetworkAdapters = $adapters
}
}
catch {
Write-Host "Error inspecting network adapters on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Checks DNS settings on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing DNS setting details.
#>
function Check-DNSSettings {
param([string[]]$Computers)
Write-Host "`nChecking DNS Settings..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$dnsSettings = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
DNSSettings = $dnsSettings
}
}
catch {
Write-Host "Error checking DNS settings on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Reviews network shares on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing network share details.
#>
function Review-NetworkShares {
param([string[]]$Computers)
Write-Host "`nReviewing Network Shares..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$shares = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-SmbShare | Select-Object Name, Path, Description
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
NetworkShares = $shares
}
}
catch {
Write-Host "Error reviewing network shares on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Analyzes network routes on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing network route details.
#>
function Analyze-NetworkRoutes {
param([string[]]$Computers)
Write-Host "`nAnalyzing Network Routes..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$routes = Invoke-Command -ComputerName $computer -ScriptBlock {
Get-NetRoute | Select-Object DestinationPrefix, NextHop, RouteMetric, InterfaceAlias
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
NetworkRoutes = $routes
}
}
catch {
Write-Host "Error analyzing network routes on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Checks remote access settings on target computers.
.PARAMETER Computers
Array of computer names to analyze.
.OUTPUTS
Array of PSObjects containing remote access setting details.
#>
function Check-RemoteAccessSettings {
param([string[]]$Computers)
Write-Host "`nChecking Remote Access Settings..." -ForegroundColor Yellow
$results = @()
foreach ($computer in $Computers) {
try {
$remoteAccess = Invoke-Command -ComputerName $computer -ScriptBlock {
$rdp = (Get-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections").fDenyTSConnections
$psRemoting = Get-PSSessionConfiguration | Select-Object -First 1 -ExpandProperty Enabled
[PSCustomObject]@{
RDPEnabled = if ($rdp -eq 0) { $true } else { $false }
PSRemotingEnabled = $psRemoting
}
} -ErrorAction Stop
$results += [PSCustomObject]@{
ComputerName = $computer
RemoteAccessSettings = $remoteAccess
}
}
catch {
Write-Host "Error checking remote access settings on $computer : $_" -ForegroundColor Red
}
}
return $results
}
<#
.SYNOPSIS
Generates a comprehensive HTML report of all analyses.
.PARAMETER AllResults
Hashtable containing all analysis results.
.OUTPUTS
Saves an HTML report to the desktop.
#>
function Generate-HTMLReport {
param([hashtable]$AllResults)
Write-Host "`nGenerating Comprehensive HTML Report..." -ForegroundColor Yellow
$reportContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Network Configuration Report</title>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; }
h1, h2, h3 { color: #0078D4; }
table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h1>Advanced Network Configuration Report</h1>
<p>Generated on: $(Get-Date)</p>
<h2>IP Configurations</h2>
$($AllResults.IPConfigurations | ConvertTo-Html -Fragment)
<h2>Firewall Rules</h2>
$($AllResults.FirewallRules | ConvertTo-Html -Fragment)
<h2>Network Adapters</h2>
$($AllResults.NetworkAdapters | ConvertTo-Html -Fragment)
<h2>DNS Settings</h2>
$($AllResults.DNSSettings | ConvertTo-Html -Fragment)
<h2>Network Shares</h2>
$($AllResults.NetworkShares | ConvertTo-Html -Fragment)
<h2>Network Routes</h2>
$($AllResults.NetworkRoutes | ConvertTo-Html -Fragment)
<h2>Remote Access Settings</h2>
$($AllResults.RemoteAccessSettings | ConvertTo-Html -Fragment)
</body>
</html>
"@
$reportContent | Out-File -FilePath $global:reportPath
Write-Host "Report generated and saved to: $global:reportPath" -ForegroundColor Green
}
# Main program loop
$targetComputers = Get-TargetComputers
$allResults = @{}
do {
Show-Menu
$choice = Read-Host "`nEnter your choice (1-9)"
switch ($choice) {
"1" { $allResults.IPConfigurations = Analyze-IPConfigurations -Computers $targetComputers }
"2" { $allResults.FirewallRules = Examine-FirewallRules -Computers $targetComputers }
"3" { $allResults.NetworkAdapters = Inspect-NetworkAdapters -Computers $targetComputers }
"4" { $allResults.DNSSettings = Check-DNSSettings -Computers $targetComputers }
"5" { $allResults.NetworkShares = Review-NetworkShares -Computers $targetComputers }
"6" { $allResults.NetworkRoutes = Analyze-NetworkRoutes -Computers $targetComputers }
"7" { $allResults.RemoteAccessSettings = Check-RemoteAccessSettings -Computers $targetComputers }
"8" { Generate-HTMLReport -AllResults $allResults }
"9" { Write-Host "Exiting program..." -ForegroundColor Yellow; break }
default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red }
}
if ($choice -ne "9") {
Read-Host "`nPress Enter to continue..."
}
} while ($choice -ne "9")
This Advanced Network Configuration Analyzer includes:
- A menu-driven interface for easy navigation.
- Functions to analyze various aspects of network configuration:
- IP Configurations
- Firewall Rules
- Network Adapters
- DNS Settings
- Network Shares
- Network Routes
- Remote Access Settings
- The ability to target all domain computers, specific computers, or read from a file.
- Comprehensive error handling for each analysis function.
- A function to generate an HTML report of all collected data.
Key features:
- Flexible target selection (all domain computers, specific computers, or from a file)
- Detailed analysis of various network configuration aspects
- Error handling to ensure the script continues even if some computers are unreachable
- HTML report generation for easy sharing and viewing of results
This tool is particularly useful for:
- Network administrators managing multiple servers or workstations
- Security auditors reviewing network configurations across an organization
- IT professionals troubleshooting network issues in a domain environment
To use this script effectively:
- Run PowerShell as an administrator
- Ensure you have the necessary permissions to query the target computers
- Have the Active Directory module installed if you plan to query all domain computers
This script provides a comprehensive overview of network configurations across multiple machines, making it easier to identify inconsistencies, security issues, or misconfigurations in a network environment.