PowerShell Code
Domain Controller Preboot Health Check
View-only PowerShell code for review.
<#
.SYNOPSIS
This function will get the domain controllers in a forest.
.DESCRIPTION
This function will get the domain controllers in a forest.
The function will read the domains in the forest and check the domain controllers in each domain.
The function will then output the domain, host name, and site of each domain controller.
The function will display the output in a table format.
The function will also handle any errors that occur during the process and continue to the next domain controller.
.EXAMPLE
Get-ForestDCs
This will run the function and get the domain controllers in the forest.
.EXAMPLE
Get-ForestDCs -ReferenceDomain "yourdomainname.com"
This will run the function and get the domain controllers in the specified domain.
.INPUTS
The domain to use as a reference for the forest.
The domain should be specified in the function.
.OUTPUTS
The function will output the domain, host name, and site of each domain controller.
The function will display the output in a table format.
.NOTES
This function is used for getting the domain controllers in a forest.
#>
Function Get-ForestDCs {
[CmdletBinding()]
param(
[string]$ReferenceDomain = $env:USERDOMAIN
)
$ForestObj = Get-ADForest -Server $ReferenceDomain
foreach($Domain in $ForestObj.Domains) {
Get-ADDomainController -Filter * -Server $Domain | Select-Object Domain,HostName,Site
}
}