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 = @( "[DCInstall]" "ReplicaOrNewDomain=Domain" "NewDomain=Forest" "NewDomainDNSName=corp.contoso.com" "ForestLevel=4" "DomainNetbiosName=CORP" "DomainLevel=4" "InstallDNS=Yes" "ConfirmGc=Yes" "CreateDNSDelegation=No" 'DatabasePath="C:\Windows\NTDS"' 'LogPath="C:\Windows\NTDS"' 'SYSVOLPath="C:\Windows\SYSVOL"' 'SafeModeAdminPassword="P@ssw0rd"' "RebootOnCompletion=Yes" ) $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.
This script works very well – Thanks for posting. Did you ever post the followup Base Configuration Scripts?
Thanks and regards
Dino
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
Joeroc,
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?
Moray
Moray,
Sure thing…I’ll email you the script shortly…
Joe
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.
Hi Friend..!!
Can U explain how did U implement this script..?? I couldn’t able to run the script…
Help Me…!!!
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?
Shankar,
It is indeed meant to be an unattended setup and it never got stuck during my testing.
Joe
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.
Thanks,
Gerald.
Gerald,
I will do my best to send you the code. Thanks for reading my blog.
Joe
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!
Thanks for taking the time to read. I choose one of the predefined templates provided by WordPress.
Excellent article. I will be dealing with a few of
these issues as well..
Highly descriptive post, I liked that bit.
Will there be a part 2?
Hi Joe, can you email your latest script for end to end creation of additional DCs? Cheers,
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.
This excellent website truly has all of the information I wanted concerning this subject and didn’t know
who to ask.