Skip to main content

Desired state configuration – xComputer domain join


Here we go again. This is just a short post on how to use the resource to join a computer to the domain. Steps we will perform:

  1. Download the resource from here. Follow the instructions to add it to the modules folder on you target computer.
  2. Create configuration data
  3. Build a very short configuration

Here is the configuration data we will use:

$ConfigData = @{  
   AllNodes = @(       
            NodeName = "*"                    
            PSDscAllowPlainTextPassword = $true
            NodeName = "localhost"      
   NonNodeData = @{
            domainName = "try.local"

A few points to note here:
  1. We have a node called “*”. It is kind of a “wildcard”, however wildcards are not supported in DSC. All key/values you specify in this node, will get inherited by all nodes. That is why I do not need to specify the PSDscAllowPlainTextPassword for my node localhost.

  2. There is something called NonNodeData. Well as the name implies, it is configuration data that is not related specifically to any node. The data is available for all nodes. i have added the FQDN for my lab domain here.

Moving on to the configuration:

configuration DomainJoin
        [pscredential] $domainCred

    node $allnodes.nodename
        xComputer join
            Name = $allnodes.nodename
            DomainName = $ConfigurationData.NonNodeData.domainName
            Credential = $domainCred

As you can see, we are using the NonNodeData in the configuration and giving the configuration the domain name to join. Here is a screenshot of the applied configuration:


That is all there is to it.



  1. Wont every computer this is run on be renamed to localhost?

  2. Hi,

    No, it will not. DSC may consist of 2 parts. Configuration data (input) and the configuration itself. The separation is there to be able to scale the configuration to the level you want. The configuration data specifies the input/information your configuration (DSC) needs to execute, like domain name, credentials and what else. When you compile the configuration, that is run it, you pass in the configuration containing the name of the nodes this configuration should apply to. I have specified "localhost" as one node and the xComputer DSC resource will execute on the localhost and join it to the domain "try.local" with the current computername. Hope that explains it?




Post a Comment

Popular posts from this blog

Developing PowerShell modules for REST APIs – Part1

Over the years I have developed different PowerShell modules for different web APIs. I thought it would be a good idea to write a 2 series post about how you could go about to do this. This will be a 2 part blog series where we will run through the entire process of building a module for a REST API. I will try my best to keep this as simple as possible and leave more advanced stuff for a follow up post if the interest is there.What you needDepending on your experience with source control and PowerShell in general, you might want to use GIT or some other software repro for the code. In addition we are going to create a test REST API using the splendid UniversalDashboard PowerShell module created by Adam Driscoll. It is available on the PowershellGallery. Other prerequisites are built-in to Powershell. I will assume that you will be following along using at least PowerShell version 5 or greater.
What is HTTP metods for REST API.The primary or most common HTTP verbs used are POST, GET, PU…

Serialize data with PowerShell

Currently I am working on a big new module. In this module, I need to persist data to disk and reprocess them at some point even if the module/PowerShell session was closed. I needed to serialize objects and save them to disk. It needed to be very efficient to be able to support a high volume of objects. Hence I decided to turn this serializer into a module called HashData.

Other Serializing methods

In PowerShell we have several possibilities to serialize objects. There are two cmdlets you can use which are built in:
Both are excellent options if you do not care about the size of the file. In my case I needed something lean and mean in terms of the size on disk for the serialized object. Lets do some tests to compare the different types:


You might be curious why I do not use the Export-CliXML cmdlet and just use the [System.Management.Automation.PSSerializer]::Serialize static method. The static method will generate the same xml, however we …

Developing PowerShell modules for REST APIs – Part2

This is part 2 of the REST API blogpost. In part1 we successfully setup two REST API endpoints using the UniversalDashboard PowerShell module. In this part we are going to create a simple module that support some CRUD operation against our API. As we are trying to keep things as simple as possible, we will not use any fancy framework (like Plaster) to build our module. We are also going to skip a very important step you should familiarize yourself with, Pester tests. Lets get to it.

The moduleWe will build a module called FilesAPI. The module folder will look like this:

In the functions folder I have already added the 2 helper functions from part 1, Get-AuthorizationHeader and ConvertTo-Base64. The other folders are just placeholders for important stuff like classes, private functions that you do not want to make available for the module consumer and tests for Pester tests. For such a small module that we are going to create, one could argue that it is much easier to just add the functi…