Skip to content

Commit

Permalink
add DHCP
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienperez committed Jan 24, 2024
1 parent 0e8f321 commit 095a6b3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DHCP/Get-DCHPRegisteredInAD.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$domain = (Get-ADDomain).DistinguishedName
Get-ADObject -SearchBase "CN=NetServices,CN=Services,CN=Configuration,$domain" -filter {ObjectClass -eq 'dHCPClass' -and Name -ne 'DHCPRoot'} -Properties * | Select-Object Name, whenCreated, distinguishedName
53 changes: 53 additions & 0 deletions DHCP/Get-DHCPADAccount.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#Requires -Version 5.0
#Requires -RunAsAdministrator

function Get-DHCPADAccount {

# check if DHCP RSAT tools are installed
$dhcpInstalled = Get-WindowsFeature -Name 'RSAT-DHCP' | Where-Object { $_.Installed -eq $true }

if (-not $dhcpInstalled) {
Write-Warning 'DHCP RSAT tools are not installed'
return
}

[System.Collections.Generic.List[PSObject]]$DHCPADAccountsArray = @()

$dhcpsInAD = Get-DhcpServerInDC

foreach ($dhcp in $dhcpsInAD) {
try {

$dhcpServerDnsCredential = Get-DhcpServerDnsCredential -ComputerName $dhcp.DnsName -ErrorAction Stop

if ($dhcpServerDnsCredential.UserName) {
$userName = $dhcpServerDnsCredential.UserName
}
else {
$userName = '-'
}
if ($dhcpServerDnsCredential.DomainName) {
$domainName = $dhcpServerDnsCredential.domainName
}
else {
$domainName = '-'
}
}
catch {
Write-Warning "$($dhcp.DnsName) - $($_.Exception.Message)"

$username = 'Error when get credentials'
$domainName = 'Error when get credentials'
}

$object = [PSCustomObject][ordered]@{
ComputerName = $dhcp.DnsName
UserName = $userName
DomainName = $domainName
}

$DHCPADAccountsArray.Add($object)
}

return $DHCPADAccountsArray
}

0 comments on commit 095a6b3

Please sign in to comment.