powershellactive-directorypowershell-dsc

AWS Directory Services - Access Denied


I am trying to use this module as part of automating AD in AWS.

Script

... Install RSAT-AD-PowerShell & xActiveDirectory ... then

Configuration DevAws
{
    Import-DscResource –ModuleName PSDesiredStateConfiguration
    Import-DscResource -Module xActiveDirectory

    Node localhost
    {
        xADUser MattCanty
        {
           UserName = "matt.canty"
           DomainName = "dev.aws"
        }
    }
}

DevAws

Start-DscConfiguration -Path ./DevAws -Wait -Verbose -Force

Log

    Directory: C:\Users\admin\Documents\DevAws


Mode                LastWriteTime         Length Name                                                                                                                    
----                -------------         ------ ----                                                                                                                    
-a----        7/18/2018   5:06 PM           1896 localhost.mof                                                                                                           
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespace
Name' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer EC2AMAZ-75TV86U with user sid S-1-5-21-264491047-2034986546-3023887121-1105.
VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ Start  Set      ]
VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ Start  Resource ]  [[xADUser]MattCanty]
VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ Start  Test     ]  [[xADUser]MattCanty]
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Retrieving Active Directory user 'matt.canty' (matt.canty@dev.aws) ...
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Active Directory user 'matt.canty' (matt.canty@dev.aws) was NOT present.
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] User 'Ensure' property is NOT in the desired state. Expected 'Present', actual 'Absent'.
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] User 'Enabled' property is NOT in the desired state. Expected 'True', actual ''.
VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ End    Test     ]  [[xADUser]MattCanty]  in 0.5470 seconds.
VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ Start  Set      ]  [[xADUser]MattCanty]
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Retrieving Active Directory user 'matt.canty' (matt.canty@dev.aws) ...
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Active Directory user 'matt.canty' (matt.canty@dev.aws) was NOT present.
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Adding Active Directory user 'matt.canty'.
Access is denied
    + CategoryInfo          : PermissionDenied: (CN=matt.canty,O...s,DC=dev,DC=aws:) [], CimException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.UnauthorizedAccessException,Microsoft.ActiveDirectory.Management.Commands.NewADUser
    + PSComputerName        : localhost

VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Retrieving Active Directory user 'matt.canty' (matt.canty@dev.aws) ...
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Active Directory user 'matt.canty' (matt.canty@dev.aws) was NOT present.
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Updating user property 'Enabled' with/to 'True'.
VERBOSE: [EC2AMAZ-75TV86U]:                            [[xADUser]MattCanty] Updating Active Directory user 'matt.canty'.
Cannot find an object with identity: 'matt.canty' under: 'DC=dev,DC=aws'.
    + CategoryInfo          : ObjectNotFound: (matt.canty:) [], CimException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetAD 
   User
    + PSComputerName        : localhost

VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ End    Set      ]  [[xADUser]MattCanty]  in 0.3440 seconds.
The PowerShell DSC resource '[xADUser]MattCanty' with SourceInfo 'C:\Users\admin\Documents\Run-AdDsc.ps1::17::9::xADUser' threw one or more non-terminating errors while 
running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more 
details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [EC2AMAZ-75TV86U]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 1.484 seconds

```

Notes

I would actually want to execute this remotely, via CloudFormation or Run Command which means I'd probably need to incorporate PSCredential somehow. I don't see how DomainAdministratorCredential on xADUser is helpful because that property isn't on xADGroup...

Any help appreciated before I start rolling my own solution!

Thanks


Solution

  • By default DSC is executed as the local system account, hence you will get access denied trying to use external resources (AD/FileShare etc)

    DomainAdministratorCredential is the one you want for xADUser, from the docs:

    [PSCredential] DomainAdministratorCredential (Write): User account credentials used to perform the task.

    for some odd reason, the property on xADGroup is just called Credential instead, though it serves the same purpose.

    [PSCredential] Credential: User account credentials used to perform the operation.