You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Details of the scenario you tried and the problem that is occurring
With the current implementation of xADDomainTrust (nor with the refactored version in PR #423) it is not possible to change the trust type. This was detected when creating integration tests.
The problem is that it is using the type [System.DirectoryServices.ActiveDirectory.Domain] or the type [System.DirectoryServices.ActiveDirectory.Forest] on which it calls the method GetTrustRelationship(). But if there already is a trust with the trust type 'Domain' and the trust should have the trust type 'Forest' the code will use the [System.DirectoryServices.ActiveDirectory.Forest] type (since the parameter TrustType = 'Forest') and no trust will be detected.
The result is that it want to create a new trust when there already is one. The logic to recreate the trust is never called since the there is no logic to check if there are a trust with either type.
Verbose logs showing the problem
Context When using configuration MSFT_xADDomainTrust_ChangeTrustType_Config
WARNING: It is not recommended to use domain credential for node 'localhost'. In order to suppress the warning, you can add a property named 'PSDscAllowDomainUser' with a value of $true to your DSC configuration data for node 'localhost'.
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer CLDC03 with user sid S-1-5-21-1619467470-1459113476-3809063323-500.
VERBOSE: [CLDC03]: LCM: [ Start Set ]
VERBOSE: [CLDC03]: [DSCEngine] Importing the module C:\Source\xActiveDirectory\DscResources\MSFT_xADDomainTrust\MSFT_xADDomainTrust.psm1 in force mode.
VERBOSE: [CLDC03]: LCM: [ Start Resource ] [[xADDomainTrust]Integration_Test]
VERBOSE: [CLDC03]: LCM: [ Start Test ] [[xADDomainTrust]Integration_Test]
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Importing the module MSFT_xADDomainTrust in force mode.
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Determining the current state of the Active Directory trust with source domain 'contoso.com', target domain 'lab.local' and context type 'Forest'. (ADDT0007)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'lab.local'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will be accessed using the 'LAB\Administrator' credentials. (ADCOMMON0048)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'contoso.com'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Determining if the trust between the 'contoso.com' and the 'lab.local' with the context type 'Forest' exists. (ADDT0001)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] There is no trust between domains 'contoso.com' and 'lab.local' with the context type 'Forest'. (ADDT0006)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'Ensure'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is 'Absent', but expected the value 'Present'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'Ensure' is not in desired state. (ADCOMMON0005)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'TrustDirection'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is '', but expected the value 'Bidirectional'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'TrustDirection' is not in desired state. (ADCOMMON0005)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'TrustType'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is '', but expected the value 'Forest'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'TrustType' is not in desired state. (ADCOMMON0005)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory trust is not in the desired state. (ADDT0009)
VERBOSE: [CLDC03]: LCM: [ End Test ] [[xADDomainTrust]Integration_Test] in 0.1400 seconds.
VERBOSE: [CLDC03]: LCM: [ Start Set ] [[xADDomainTrust]Integration_Test]
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Importing the module MSFT_xADDomainTrust in force mode.
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'lab.local'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will be accessed using the 'LAB\Administrator' credentials. (ADCOMMON0048)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'contoso.com'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'lab.local'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will be accessed using the 'LAB\Administrator' credentials. (ADCOMMON0048)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'contoso.com'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Determining if the trust between the 'contoso.com' and the 'lab.local' with the context type 'Forest' exists. (ADDT0001)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] There is no trust between domains 'contoso.com' and 'lab.local' with the context type 'Forest'. (ADDT0006)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'Ensure'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is 'Absent', but expected the value 'Present'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'Ensure' is not in desired state. (ADCOMMON0005)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'TrustDirection'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is '', but expected the value 'Bidirectional'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'TrustDirection' is not in desired state. (ADCOMMON0005)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Evaluating the state of the property 'TrustType'. (ADCOMMON0003)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] String value does not match. Current value is '', but expected the value 'Forest'. (ADCOMMON0008)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The parameter 'TrustType' is not in desired state. (ADCOMMON0005)
[-] Should compile and apply the MOF without throwing 1.35s
Expected no exception to be thrown, but an exception "Exception calling "CreateTrustRelationship" with "2" argument(s): "A forest trust relationship exists between "contoso.com" and "lab.local"."" was thrown from C:\Source\xActiveDir
ectory\Tests\Integration\MSFT_xADDomainTrust.Integration.Tests.ps1:161 char:21
+ ... Start-DscConfiguration @startDscConfigurationParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
162: } | Should -Not -Throw
at <ScriptBlock>, C:\Source\xActiveDirectory\Tests\Integration\MSFT_xADDomainTrust.Integration.Tests.ps1: line 143
VERBOSE: An LCM method call arrived from computer CLDC03 with user sid S-1-5-21-1619467470-1459113476-3809063323-500.
WARNING: [CLDC03]: [] The GET operation will be carried against a pending configuration since the latest configuration has not converged yet.
VERBOSE: [CLDC03]: [DSCEngine] Importing the module C:\Source\xActiveDirectory\DscResources\MSFT_xADDomainTrust\MSFT_xADDomainTrust.psm1 in force mode.
VERBOSE: [CLDC03]: LCM: [ Start Get ]
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Importing the module MSFT_xADDomainTrust in force mode.
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'lab.local'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will be accessed using the 'LAB\Administrator' credentials. (ADCOMMON0048)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The type 'System.DirectoryServices.ActiveDirectory.DirectoryContext' is already loaded into the PowerShell session. (ADCOMMON0043)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Get a new Active Directory context of the type 'Forest'. (ADCOMMON0046)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] The Active Directory context will target 'contoso.com'. (ADCOMMON0047)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] Determining if the trust between the 'contoso.com' and the 'lab.local' with the context type 'Forest' exists. (ADDT0001)
VERBOSE: [CLDC03]: [[xADDomainTrust]Integration_Test] There is no trust between domains 'contoso.com' and 'lab.local' with the context type 'Forest'. (ADDT0006)
VERBOSE: [CLDC03]: LCM: [ End Get ] [[xADDomainTrust]Integration_Test] in 0.0780 seconds.
VERBOSE: [CLDC03]: LCM: [ End Get ] in 0.1560 seconds.
[+] Should be able to call Get-DscConfiguration without throwing 555ms
[-] Should have set the resource and all the parameters should match 25ms
Expected strings to be the same, but they were different.
Expected length: 7
Actual length: 6
Strings differ at index 0.
Expected: 'Present'
But was: 'Absent'
177: $resourceCurrentState.Ensure | Should -Be 'Present'
at <ScriptBlock>, C:\Source\xActiveDirectory\Tests\Integration\MSFT_xADDomainTrust.Integration.Tests.ps1: line 177
Suggested solution to the issue
Option 1
Add logic to call the method GetTrustRelationship() for both the types [System.DirectoryServices.ActiveDirectory.Domain] and [System.DirectoryServices.ActiveDirectory.Forest] in Get-TargetResource to really determine if there is a trust present.
Option 2
Use the cmdlet Get-ADTrust available in ActiveDirectoy powershell module. It will return the trust regardless of trust type.
Details of the scenario you tried and the problem that is occurring
With the current implementation of xADDomainTrust (nor with the refactored version in PR #423) it is not possible to change the trust type. This was detected when creating integration tests.
The problem is that it is using the type
[System.DirectoryServices.ActiveDirectory.Domain]
or the type[System.DirectoryServices.ActiveDirectory.Forest]
on which it calls the methodGetTrustRelationship()
. But if there already is a trust with the trust type'Domain'
and the trust should have the trust type'Forest'
the code will use the[System.DirectoryServices.ActiveDirectory.Forest]
type (since the parameterTrustType = 'Forest'
) and no trust will be detected.The result is that it want to create a new trust when there already is one. The logic to recreate the trust is never called since the there is no logic to check if there are a trust with either type.
Verbose logs showing the problem
Suggested solution to the issue
Option 1
Add logic to call the method
GetTrustRelationship()
for both the types[System.DirectoryServices.ActiveDirectory.Domain]
and[System.DirectoryServices.ActiveDirectory.Forest]
inGet-TargetResource
to really determine if there is a trust present.Option 2
Use the cmdlet
Get-ADTrust
available in ActiveDirectoy powershell module. It will return the trust regardless of trust type.The cmdlet
Get-ADTrust
will fail if the trust does not existThe DSC configuration that is used to reproduce the issue (as detailed as possible)
The operating system the target node is running
Windows Server 2019
Version and build of PowerShell the target node is running
n/a
Version of the DSC module that was used ('dev' if using current dev branch)
Dev
The text was updated successfully, but these errors were encountered: