Skip to content

Commit

Permalink
Fix Add DHCP Infrastructure information AsBuiltReport#180
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelinux committed Jun 15, 2024
1 parent 61b73c2 commit 084a48c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [#174](https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.AD/issues/174)
- Fix [#176](https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.AD/issues/176)
- Fix [#178](https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.AD/issues/178)
- Fix [#180](https://github.com/AsBuiltReport/AsBuiltReport.Microsoft.AD/issues/180)

## [0.8.1] - 2024-05-16

Expand Down
79 changes: 79 additions & 0 deletions Src/Private/Get-AbrDHCPinAD.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
function Get-AbrDHCPinAD {
<#
.SYNOPSIS
Used by As Built Report to retrieve Microsoft AD DHCP Servers information
.DESCRIPTION
.NOTES
Version: 0.8.2
Author: Jonathan Colon
Twitter: @jcolonfzenpr
Github: rebelinux
.EXAMPLE
.LINK
#>
[CmdletBinding()]
param (
)

begin {
Write-PScriboMessage "Collecting AD DHCP Servers information of $($ForestInfo.toUpper())."
}

process {
$DomainInfo = Invoke-Command -Session $TempPssSession { Get-ADDomain ($using:ADSystem).RootDomain -ErrorAction Stop }
if ($DomainInfo) {
$DHCPServers = try {
Get-ADObjectSearch -DN "CN=NetServices,CN=Services,CN=Configuration,$(($DomainInfo).DistinguishedName)" -Filter { objectclass -eq 'dHCPClass' -AND Name -ne 'dhcproot' } -Properties "*" -SelectPrty 'Name' -Session $TempPssSession
} catch { Out-Null }
}
try {
if ($DHCPServers ) {
try {
$DCServersinAD = @(foreach ($Domain in $ADSystem.Domains) {
(Invoke-Command -Session $TempPssSession -ErrorAction Stop { Get-ADDomain -Identity $using:Domain }).ReplicaDirectoryServers
})
} catch { Out-Null }
Section -Style Heading3 'DHCP Infrastructure' {
Paragraph "The following section provides a summary of the DHCP infrastructure configured on Active Directory."
BlankLine
$DCHPInfo = @()
foreach ($DHCPServer in $DHCPServers) {
try {
$inObj = [ordered] @{
'Server Name' = $DHCPServer.Name
'Is Domain Controller?' = Switch ($DHCPServer.Name -in $DCServersinAD) {
$True {'Yes'}
$false {'No'}
default {'Unknown'}
}
}
$DCHPInfo += [pscustomobject]$inobj
} catch {
Write-PScriboMessage -IsWarning "$($_.Exception.Message) (DHCP Item)"
}
}

$TableParams = @{
Name = "DHCP Infrastructure - $($ForestInfo.toUpper())"
List = $false
ColumnWidths = 50, 50
}
if ($Report.ShowTableCaptions) {
$TableParams['Caption'] = "- $($TableParams.Name)"
}
$DCHPInfo | Sort-Object -Property 'Server Name' | Table @TableParams
}
} else {
Write-PScriboMessage -IsWarning "No DHCP Infrastructure information found in $($ForestInfo.toUpper()), disabling the section."
}
} catch {
Write-PScriboMessage -IsWarning "$($_.Exception.Message) (DHCP Table)"
}
}

end {}

}
5 changes: 5 additions & 0 deletions Src/Private/Get-AbrForestSection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function Get-AbrForestSection {
} catch {
Write-PScriboMessage -IsWarning $_.Exception.Message
}
try {
Get-AbrDHCPinAD
} catch {
Write-PScriboMessage -IsWarning $_.Exception.Message
}
}
} catch {
Write-PScriboMessage -IsWarning "Error: Unable to retreive Forest: $ForestInfo information."
Expand Down

0 comments on commit 084a48c

Please sign in to comment.