Private/Get-DomainPWDetails.ps1

<#
.SYNOPSIS
Collects domain details and the default password policy.
 
.DESCRIPTION
Collects domain identity, password-policy settings, machine-account quota, and enabled-user
counts for the specified domain.
 
.COMPONENT
Category: Sub Function
 
.FUNCTIONALITY
Returns domain metadata, password settings, machine-account quota, and enabled-user count.
#>

function Get-DomainPWDetails {

    Param([string]$DomainName)

    $Info = Measure-FunctionRuntime -Begin


    try {
        $DomainInfo = Get-ADDomain -Server $DomainName
        $DomainObject = Get-ADObject -Identity $DomainInfo.DistinguishedName -Properties 'ms-DS-MachineAccountQuota' -Server $DomainName
        $PWPOlicy = Get-ADDefaultDomainPasswordPolicy -Server $DomainName

        [PSCustomObject]@{
            DomainType                  = $Script:DoaminTypes[$DomainInfo.DNSRoot]
            DomainFQDN                  = $DomainInfo.DNSRoot
            DomainDN                    = $DomainInfo.DistinguishedName
            DomainName                  = $DomainInfo.DNSRoot.Split('.')[0]
            NetBIOSName                 = $DomainInfo.NetBIOSName
            DomainSID                   = $DomainInfo.DomainSID.Value
            DomainMode                  = $DomainInfo.DomainMode
            MachineAccountQuota         = $DomainObject.'ms-DS-MachineAccountQuota'
            IsRootDomain                = ($DomainInfo.DNSRoot -eq $Forest.RootDomain)
            IsCurrentDomain             = If ($DomainInfo.DNSRoot -eq $CurrentDomain) { "Yes" } else { "" }
            PdcRoleOwner                = $DomainInfo.PDCEmulator
            NearestRWDC                 = $DomainInfo.InfrastructureMaster
            ComplexityEnabled           = $PWPOlicy.ComplexityEnabled
            MinPasswordLength           = $PWPOlicy.MinPasswordLength
            LockoutThreshold            = $PWPOlicy.LockoutThreshold
            LockoutDuration             = $PWPOlicy.LockoutDuration
            LockoutObservationWindow    = $PWPOlicy.LockoutObservationWindow
            MaxPasswordAge              = $PWPOlicy.MaxPasswordAge
            MinPasswordAge              = $PWPOlicy.MinPasswordAge
            ReversibleEncryptionEnabled = $PWPOlicy.ReversibleEncryptionEnabled
            EnabledUser                 = Get-ADUser -Filter 'Enabled -eq $true' -Server $($DomainInfo.DNSRoot) -SearchBase $($DomainInfo.DistinguishedName) | Measure-Object | Select-Object -ExpandProperty Count
        }
    }
    catch {
        
    }


    Measure-FunctionRuntime -End -Details $Info
}