Private/Helper/Test-IsADJoined.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Test-IsADJoined {
    <#
    .SYNOPSIS
    Determines if the system is joined to an Active Directory domain.
 
    .DESCRIPTION
    This function checks the domain services registration status to determine if the system is joined to an Active Directory domain.
 
    .PARAMETER None
 
    .EXAMPLE
    Test-IsADJoined
 
    .NOTES
    The function uses the dsregcmd command to check the domain joined status.
    #>


    $DomainServicesRegistration = dsregcmd /status

    IF ($DomainServicesRegistration -like "*DomainJoined : YES*") { RETURN $True }
    ELSEIF ($DomainServicesRegistration -like "*AzureAdJoined : YES*" -and $DomainServicesRegistration -like "*DomainJoined : NO*") { RETURN $False }
    ELSEIF ($DomainServicesRegistration -like "*AzureAdJoined : NO*" -and $DomainServicesRegistration -like "*DomainJoined : NO*") { RETURN $False }
    ELSE { RETURN $False }
}