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 #> 


Revision #1
Created 23 December 2023 04:07:16 by ColtM
Updated 13 June 2024 01:28:02 by ColtM