Skip to main content

Search all DHCP servers in a domain for a hostname

Get-DhcpServerInDC <#| ?{ $_.DnsName -notmatch "rhsc-01-vsrv04"} #> | % { 

$_.DnsName 

  $ServerName = $_.DnsName 

  try { 

    Get-DhcpServerv4Scope -ComputerName $ServerName -erroraction continue <#| ?{ $_.Name -notmatch "Guest" }#> | %{  $Scope = $_.ScopeId 

        <#Write-Host -ForegroundColor Yellow "Working on $Scope"#> 

        try { 

          Get-DhcpServerv4Lease -computername $ServerName -ScopeId $Scope | Where-Object {$_.HostName -iLike '*win7*'} 

        } catch { 

        } 

    } 

  } catch { 

   

  } 

} <# | Out-File C:\Accent\DHCP.txt #>