Private/Helper/Test-IsInWorkgroup.ps1

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


FUNCTION Test-IsInWorkgroup {
    <#
    .SYNOPSIS
    Determines if the system is in a workgroup.
 
    .DESCRIPTION
    This function checks the domain services registration status to determine if the system is in a workgroup.
 
    .PARAMETER None
 
    .EXAMPLE
    Test-IsInWorkgroup
 
    .NOTES
    The function uses the dsregcmd command to check the workgroup status.
    #>


    $DomainServicesRegistration = dsregcmd /status

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