Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xComputer: Error When Joining a Domain and Renaming a Computer when JoinOU is specified #221

Closed
X-Guardian opened this issue Jun 6, 2019 · 1 comment · Fixed by #222
Closed
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@X-Guardian
Copy link
Contributor

X-Guardian commented Jun 6, 2019

Details of the scenario you tried and the problem that is occurring

When applying an xComputer resource that requires the computer to be renamed and join a domain concurrently, the following error is thrown: The directory service is busy.

Verbose logs showing the problem

VERBOSE: [EC2AMAZ-L43BSB0]: LCM:  [ Start  Resource ]  [[Computer]ComputerName]
VERBOSE: [EC2AMAZ-L43BSB0]: LCM:  [ Start  Test     ]  [[Computer]ComputerName]
VERBOSE: [EC2AMAZ-L43BSB0]:                            [[Computer]ComputerName] Testing computer state for 'CS02-EUW1'.
VERBOSE: [EC2AMAZ-L43BSB0]: LCM:  [ End    Test     ]  [[Computer]ComputerName]  in 0.0160 seconds.
VERBOSE: [EC2AMAZ-L43BSB0]: LCM:  [ Start  Set      ]  [[Computer]ComputerName]
VERBOSE: [EC2AMAZ-L43BSB0]:                            [[Computer]ComputerName] Setting computer state for 'CS02-EUW1'.
VERBOSE: [EC2AMAZ-L43BSB0]:                            [[Computer]ComputerName] Perform operation 'Enumerate CimInstances' with following parameters, ''namespaceName' = root\cimv2,'className' = Win32_ComputerSystem'.
VERBOSE: [EC2AMAZ-L43BSB0]:                            [[Computer]ComputerName] Operation 'Enumerate CimInstances' complete.
>> TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy."
>> TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy."
>> TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy."
>> TerminatingError(): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy."
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy.
Computer 'EC2AMAZ-L43BSB0' was successfully joined to the new domain
'contoso.com', but renaming it to 'CS02-EUW1' failed with the following
error message: The directory service is busy.

Suggested solution to the issue

This is a problem with the Add-Computer cmdlet that is being used by the resource. The following stand-alone code reproduces the error:

$addComputerParameters = @{
    DomainName = 'contoso.com'
    Credential = Get-Credential
    Force      = $true
    OUPath     = 'ou=Servers,dc=contoso,dc=com'
    NewName    = 'CS02-EUW1'
}
Add-Computer @addComputerParameters

Add-Computer : Computer 'TEST02' was successfully joined to the new domain 'contoso.com', but renaming it to 'CS02-EUW1' failed with the following error message: The directory service is busy.
At line:1 char:1
+ Add-Computer @addComputerParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (TEST02:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : FailToRenameAfterJoinDomain,Microsoft.PowerShell.Commands.AddComputerCommand

Whereas the same code but without the OUPath parameter works successfully each time:

$addComputerParameters = @{
    DomainName = 'contoso.com'
    Credential = Get-Credential
    Force      = $true
    NewName    = 'CS02-EUW1'
}
Add-Computer @addComputerParameters

Suggested workaround for this issue

Trap for this error when calling Add-Computer, and then perform a Rename-Computer if it has occured. Sample code:

$addComputerParameters = @{
    DomainName = 'contoso.com'
    Credential = Get-Credential
    Force      = $true
    OUPath     = 'ou=Servers,dc=contoso,dc=com'
    NewName    = 'CS02-EUW1'
}

try {
    Add-Computer @addComputerParameters
}
catch [System.InvalidOperationException]  {
    if ($_.Exception.message -like '*The directory service is busy*') {
        Rename-Computer -NewName $Name -DomainCredential $Credential
    }
catch {
    throw $_
    }
}

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration DomainNameDsc {
    <#
    .DESCRIPTION
        The DomainNameDsc sets the computer name and joins the computer to the specified domain
    #>

    param (
        # Specifies the Computer Name
        [Parameter(Mandatory)]
        [String]$ComputerName,
        # Specifies the Domain Name
        [Parameter(Mandatory)]
        [String]$DomainName,
        # Specifies the Domain Join Credentials
        [Parameter(Mandatory)]
        [PSCredential]$Credential,
        # Specifies the distinguished name of the organizational unit that the computer account will be created in
        [Parameter(Mandatory)]
        [String]$OU
    )

    Import-DscResource -ModuleName xActiveDirectory   # https://github.com/PowerShell/xActiveDirectory
    Import-DscResource -Module ComputerManagementDsc  # https://github.com/PowerShell/ComputerManagementDsc

    Node $AllNodes.NodeName {
        Computer ComputerName {
            Name       = $ComputerName
            DomainName = $DomainName
            JoinOU     = $OU
            Credential = $Credential
            DependsOn  = '[xWaitForADDomain]WaitForADDomain'
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.2969.amd64fre.rs1_release.190503-1820
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.14393.2969
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2969
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.4.0.0    ComputerManagementDsc
@X-Guardian X-Guardian changed the title xComputer: Error When Joining a Domain and Renaming a Computer when a JoinOU is specified xComputer: Error When Joining a Domain and Renaming a Computer when JoinOU is specified Jun 6, 2019
@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Jun 7, 2019
@X-Guardian
Copy link
Contributor Author

Here is a clixml export of the error produced: DomainJoinBusyError.clixml.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants