PowerShell - DHCP Server Heath Check
$dhcpServer = "<DHCPServerName>"
if (Test-Connection -ComputerName $dhcpServer -Count 1 -Quiet) {
Write-Host "DHCP
server '$dhcpServer' is reachable."
$dhcpService = Get-Service -ComputerName
$dhcpServer -Name
DHCPServer
if ($dhcpService.Status -eq "Running") {
Write-Host "DHCP
service on server '$dhcpServer' is running."
} else {
Write-Host "DHCP
service on server '$dhcpServer' is not running."
}
$dhcpScopes = Get-DhcpServerv4Scope -ComputerName
$dhcpServer
# Check status and leases for each scope
foreach ($scope
in $dhcpScopes)
{
Write-Host "DHCP
Scope: $($scope.Name)"
Write-Host "---------------------------"
# Check scope status
Write-Host "Scope
ID: $($scope.ScopeId)"
Write-Host "Subnet: $($scope.SubnetMask)"
Write-Host "State: $($scope.State)"
Write-Host "Start
Range: $($scope.StartRange)"
Write-Host "End
Range: $($scope.EndRange)"
Write-Host "Lease
Duration: $($scope.LeaseDuration)"
Write-Host ""
# Get lease count for the scope
$leasesCount =
(Get-DhcpServerv4Lease -ComputerName
$dhcpServer -ScopeId
$scope.ScopeId).Count
Write-Host "Number
of Leases: $leasesCount"
Write-Host "---------------------------"
Write-Host ""
}
}
else {
Write-Host "DHCP
server '$dhcpServer' is not reachable."
}
No comments:
Post a Comment