DHCP - Report for all DHCP scopes with detail

Script for DHCP scope report:


$DHCP_Scopes = Get-DhcpServerv4Scope –ComputerName FQDN -ErrorAction Stop

           #$DHCP_Scopes = $Null

    $output = Foreach ($DHCP_Scope in $DHCP_Scopes) {

        # Going through the scopes returned in a given server

        $DHCP_Scope_Stats = Get-DhcpServerv4ScopeStatistics -ComputerName FQDN -ScopeId $DHCP_Scope.ScopeId

        [PSCustomObject] @{

            'DHCP Server'    = $DHCP_Server.DNSName

            'DHCP IP'        = $DHCP_Server.IPAddress

            'Scope ID'       = $DHCP_Scope.ScopeId.IPAddressToString

            'Scope Name'     = $DHCP_Scope.Name

            'Scope State'    = $DHCP_Scope.State

            'In Use'         = $DHCP_Scope_Stats.InUse

            'Free'           = $DHCP_Scope_Stats.Free

            '% In Use'       = ([math]::Round($DHCP_Scope_Stats.PercentageInUse, 0))

            'Reserved'       = $DHCP_Scope_Stats.Reserved

            'Subnet Mask'    = $DHCP_Scope.SubnetMask

            'Start Range'    = $DHCP_Scope.StartRange

            'End Range'      = $DHCP_Scope.EndRange

            'Lease Duration' = $DHCP_Scope.LeaseDuration

        }

    }

    $output | export-csv $env:userprofile\desktop\DHCP-REPORT.csv


Comments

Popular posts from this blog

altiris software key

Service Principal Names (SPNs) SetSPN Syntax (Setspn.exe)

Troubleshooting Netlogon Error Codes