Why is xComputer not joining domain

This should be simple, but I can’t seem to figure out what is wrong. I’m trying to use DSC to create a small environment in Azure. I can successfully promote a domain controller and install DNS, but adding nodes to the domain is not working. The node configuration is below, it successfully changes the DNS server address then shows as compliant after running for only 22 seconds. I can join the domain manually without issue.

        xDnsServerAddress SetDnsServer
        {
            Address = '192.168.10.10'
            InterfaceAlias = 'Ethernet'
            AddressFamily = 'IPv4'
        }

        xWaitForADDomain ForestWait 
        { 
            DomainName = 'MyDomain.local'
            RetryCount = 40 
            RetryIntervalSec = 30
            DomainUserCredential = $domainCredentials
            DependsOn = "[xDnsServerAddress]SetDnsServer"
        }
            
        xComputer JoinDomain  
        {
            Name = $env:COMPUTERNAME
            DomainName = 'MyDomain.local'
            Credential = $domainCredentials
            DependsOn = "[xWaitForADDomain]ForestWait"
        }

Have you ever made the $env:COMPUTERNAME work? I ask because that’s going to resolve to the name of the computer where the configuration script is run. It’s not going to go into the MOF like that.

Provided you’re not using ‘localhost’, you could use $Node.

Although that also assumes you’re not trying to change the computer name at the same time.

Unfortunately the resource requires setting the machine name in the config which as you can guess doesn’t work very will if you are trying to work under the whole one config running on lots of server principle. There resource currently doesn’t appear to have any logic around it working “dynamically”.

There is a issue raised on Github where we are asking for the Machine name not be a mandatory parameter but since it is the key in the resource that most likely won’t happen. They would need to allow it to accept localhost where it then will then check the node being configured for it’s name from the environmental variable.

https://github.com/PowerShell/xComputerManagement/issues/29

In Azure the machine name is set when you create the machine so outside of DSC maintaining what the machine is called there really isn’t a need for DSC to set the name of the machine and join it to the domain.

In the meantime since there is no actual requirement to set the machine name when you are doing a domain join operation I’ve stripped out the majority of the logic in xComputer surrounding the machine name (Which is basically the majority of the resource) but kept everything else until they’ve re-worked the xComputer module.

This covers my specific scenario where I have vCloud sysprepping the machine and setting the machine name already, which is basically what Azure is doing. You can search the powershell gallery for xDSCDomainjoin.