Home > Powershell > Powershell: Domain Controller Automation

Powershell: Domain Controller Automation

I’ve recently completed the following Microsoft Test Lab Guides:

The DirectAccess lab required that the Base Configuration be setup first and considering that both labs were time consuming and, at times remedial, I decided to make the process more streamlined and automated by using Powershell to create a script ( for complete automation ) which I could  then convert into a module ( for a more step by step approach ).  I’m still in the begining phase of automating the Base Configuration but I’ve already created a few functions, one of which will turn a standalone server into the first Domain Controller for the Corp.Contoso.Com domain. 

Function Configure-DomainController {            

   #Importing the ServerManager module to make use of Add-WindowsFeature cmdlet
    import-module servermanager
    add-windowsfeature adds-domain-controller            

    #Create an unattend.txt file to automate the DCPROMO process
    $unattend = "c:\unattend.txt"
    if(!(test-path $unattend)) { new-item $unattend -type file }
    $content = @(
    $content | out-file $unattend
    $dcpromo = "dcpromo /unattend:$unattend"
    invoke-expression -command $dcpromo
  }#end Function 

I’ve tested it out serveral times using Hyerp-V and snapshots (another time saver) and it works perfectly.   I was going to include the unattend.txt file separately along with script but decided to have the function create it so that the function could be used independently and would be less prone to error.

Categories: Powershell
  1. March 13, 2012 at 11:51 pm

    This script works very well – Thanks for posting. Did you ever post the followup Base Configuration Scripts?
    Thanks and regards

    • joeroc
      March 23, 2012 at 7:14 pm

      I did add additional code to the script that did the following:
      -Configured script to run as a scheduled task
      -Rename the server
      -Configure IP Settings
      -Reboot and rename and dcpromo

      • Moray Sandison
        October 2, 2012 at 5:46 pm


        We are trying to automate the build and promotion of DCs to an existing domain to streamline our processes and ensure uniformity accross all DCs. Can you tell me if you could share the codes that you put together for the start to finish build and promotion so we could adapt as neccesary and not reinvent the wheel?


      • joeroc
        October 2, 2012 at 7:38 pm


        Sure thing…I’ll email you the script shortly…


      • Jeremy
        February 4, 2014 at 4:00 pm

        Hello, I know this is an old thread, but was wondering if you were able to email me the final script on this?

        Thanks for your help.

    • Kamesh Kumar
      August 8, 2012 at 11:41 am

      Hi Friend..!!
      Can U explain how did U implement this script..?? I couldn’t able to run the script…
      Help Me…!!!

  2. December 18, 2012 at 7:25 am

    Hi, thanks for the great script. It works pretty well except at some points its get stuck and then when you click enter it resumes its execution. I am sure if this is unattended setup then it must not wait for user`s any action. Am I mistaken something?

    • joeroc
      February 22, 2013 at 11:57 pm


      It is indeed meant to be an unattended setup and it never got stuck during my testing.


  3. January 15, 2013 at 5:03 pm

    I am constantly building servers in hyper-v to test some feature or study new product. Your script is a really good idea and has pushed me to look closer at powershell. If you are willing to share your code one more time, I will give it a real work-out and maybe even useful feedback.

    • joeroc
      February 22, 2013 at 11:53 pm


      I will do my best to send you the code. Thanks for reading my blog.


  4. May 24, 2013 at 6:48 am

    I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable
    for me to come here and visit more often.
    Did you hire out a developer to create your theme? Outstanding work!

    • joeroc
      May 26, 2013 at 3:55 pm

      Thanks for taking the time to read. I choose one of the predefined templates provided by WordPress.

  5. June 5, 2013 at 3:23 pm

    Excellent article. I will be dealing with a few of
    these issues as well..

  6. July 18, 2014 at 4:51 am

    Highly descriptive post, I liked that bit.
    Will there be a part 2?

  7. Alex
    October 3, 2014 at 9:02 pm

    Hi Joe, can you email your latest script for end to end creation of additional DCs? Cheers,

  8. November 14, 2014 at 1:50 am

    hello there and thank you for your information – I’ve definitely picked up something new from right here.
    I did however expertise some technical issues using this web site, since
    I experienced to reload the website lots of times previous to I could get it to load
    properly. I had been wondering if your web hosting is OK?

    Not that I am complaining, but slow loading instances times
    will often affect your placement in google and could damage your high quality score if advertising and marketing with Adwords.
    Well I’m adding this RSS to my email and can look out for
    much more of your respective intriguing content. Make sure you update this again soon.

  9. May 13, 2018 at 12:12 am

    This excellent website truly has all of the information I wanted concerning this subject and didn’t know
    who to ask.

  1. February 19, 2013 at 11:56 am
  2. May 4, 2018 at 2:00 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: