Requirements: The business needs to obtain the current DHCP server all address lease information.
1. First look at the DHCP-related Help information:
2. Determine the execution of the command and get help information about it: Assist Get-dhcpserverv4scope
Name Get-dhcpserverv4scope
Grammar Get-dhcpserverv4scope [[-scopeid] <ipaddress[]>] [-computername <string>] [-cimsession <CimSession[ ]>] [-throttlelimit <int>] [-asjob] [<commonparameters>]
3. View the address lease information under a scope:
Get-dhcpserverv4lease-computername 10.10.32.26-scopeid 10.10.33.0
4. Query the lease information for all scopes:
Get-dhcpserverv4scope | Get-dhcpserverv4lease
5. Export the information you have queried to a CSV file:
6. Filter the required fields according to your needs, to prevent character errors everywhere (you can specify characters), and export the CSV file:
Get-dhcpserverv4scope | Get-dhcpserverv4lease | Select-object Ipaddress,addressstate,clientid,hostname,leaseexpirytime | Export-csv C:\DHCPInfo.csv-Encoding utf8-notypeinformation
The operation is complete.
get-dhcp* Supplement:
Get-dhcp serverv4binding Gets the IPv4 interface on the computer that is bound to the DHCP Server service.
GET-DHCP Serverv4class retrieves the IPV4 vendor or user class from the DHCP Server service.
GET-DHCP serverv4dnssetting Gets the DNS settings that are configured on the DHCP Server service for a specific range, reservation, or server level.
GET-DHCP Serverv4exclusionrange returns the range of IPV4 addresses that are excluded from the specified range ID.
Get-dhcp Serverv4failover Gets the failover relationship that is configured on the DHCP Server service for a specific failover relationship name.
Get-dhcp Serverv4filter Gets the list of allowed MAC addresses or denied lists on the DHCP Server service.
Get-dhcp Serverv4filterlist Gets the enabled state of the Allow filter list and rejects the filter list set on the DHCP Server service.
Get-dhcp Serverv4freeipaddress Gets the free IPv4 address from the specified range.
Get-dhcp Serverv4lease obtains one or more lease records from the DHCP Server service.
GET-DHCP Serverv4multicastexclusionrange retrieves the exclusion range for the specified multicast scope.
GET-DHCP Serverv4multicastlease retrieves a multicast lease that specifies the domain name of the action.
Get-dhcp Serverv4multicastscope Gets the multicast scope object.
GET-DHCP serverv4multicastscopestatistics gets multicast scope statistics.
Get-dhcp serverv4optiondefinition gets the DHCPV4 option definition for the specified option ID.
Get-dhcp Serverv4optionvalue returns the IPV4 option value for the IPV4 option at the server, scope, or reservation level.
GET-DHCP Serverv4policy Gets the server-level or scope-level policies.
Get-dhcp Serverv4policyiprange Gets the IP address range from the policy in the specified range.
Get-dhcp Serverv4reservation Gets the IPv4 reservation for the IP address or client ID.
Get-dhcp Serverv4scope Returns the IPV4 scope configuration for the specified scope.
Get-dhcp Serverv4scopestatistics Gets the IPV4 range statistics corresponding to the IPV4 range ID specified for the DHCP Server service.
Get-dhcp Serverv4statistics Gets the DHCP Server service statistics for IPV4.
Get-dhcp Serverv4superscope Gets the configuration of the specified superclass.
GET-DHCP Serverv4superscopestatistics returns statistics for super users.
Get-dhcpserverv4lease Basic Example:
EG1: Gets all active IPV4 address leases from DHCPV4 scope 10.10.34.0.
Get-dhcpserverv4lease-computername dhcpserver (FQDN&IP)-scopeid 10.10.34.0
EG2: Get IPv4 address 10.10. 34.10 and 10.10.33.10 IP address lease information.
Get-dhcpserverv4lease-computername dhcpserver (FQDN&IP)-ipaddress 10.10.34.11, 10.10.33.1
EG3: From DHCPv4 example 10.10. 34.0 get all bad or rejected IPV4 address leases.
Get-dhcpserverv4lease-computername dhcpserver (FQDN&IP)-scopeid 10.10.34.0-badleases
EG4: Gets all types of IPV4 address leases from the DHCPv4 range 10.10.34.0, including activity, rejected, and expired.
Get-dhcpserverv4lease-computername dhcpserver (FQDN&IP)-scopeid 10.10.34.0-allleases
EG5: Gets all active IP address leases for all scopes on the DHCP Server service that is running on the computer named DHCPServer (FQDN&IP). The Get-dhcpserverv4scope cmdlet returns the scope object and passes the object to the cmdlet, which returns the active address lease object in all scopes.
Get-dhcpserverv4scope-computername dhcpserver (FQDN&IP) | Get-dhcpserverv4lease-computername DHCPServer (FQDN&IP)
powershell-Obtaining DHCP address lease information