If you need to get all DHCP server leases within your network you could use Windows Server 2012 DHCP cmdlets for the task. You need to install the DHCP RSAT module on the server.
$dhcpservers= Get-DhcpServerInDC
$scope= @()
$reportdata= @()
$ping=new-object System.Net.NetworkInformation.Ping
foreach ($dhcpserverin$dhcpservers )
{
$reply=$null
$Reply=$ping.send($dhcpserver.DnsName)
If ($reply.status -eq“Success”)
{
$scopes= Get-DhcpServerv4Scope -ComputerName $dhcpserver.dnsname
If ($scopes-ne$null)
{
foreach ($scopein$scopes)
{
$Leases= Get-DhcpServerv4Lease -ScopeId $scope.ScopeId -ComputerName $dhcpserver.dnsname
Foreach ($leasein$Leases) {
write-host$ Lease.IPAddress $Lease.HostName
$reportdata+=New-Object-TypeNamePSObject-Property @{
Server =$dhcpserver.dnsname
Scope =$Lease.ScopeId
IP =$Lease.IPAddress
Mac =$Lease.ClientID
View original post 56 more words