-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Labels
bugThe issue is a bug.The issue is a bug.help wantedThe issue is up for grabs for anyone in the community.The issue is up for grabs for anyone in the community.
Description
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.AddComputerCommandWhereas 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 @addComputerParametersSuggested 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
Metadata
Metadata
Assignees
Labels
bugThe issue is a bug.The issue is a bug.help wantedThe issue is up for grabs for anyone in the community.The issue is up for grabs for anyone in the community.