-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e8f321
commit 095a6b3
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |