{"id":2651,"date":"2013-10-28T00:01:00","date_gmt":"2013-10-28T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/10\/28\/building-a-demo-active-directory-part-1\/"},"modified":"2013-10-28T00:01:00","modified_gmt":"2013-10-28T00:01:00","slug":"building-a-demo-active-directory-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/building-a-demo-active-directory-part-1\/","title":{"rendered":"Building a Demo Active Directory: Part 1"},"content":{"rendered":"<p><strong>Summary<\/strong>: Leverage Windows PowerShell in Windows Server&nbsp;2012 to create a new Active Directory forest.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy!<\/p>\n<p>I often have to put together demo environments, and I need a new empty Active Directory forest. Is there any way I can do this faster than by using the GUI&hellip;maybe with Windows PowerShell?<\/p>\n<p>&mdash;TM<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello TM,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney here, filling in for our good friend, Ed.<\/p>\n<p>I&rsquo;ve also had to build demo environments&mdash;sometimes as a proof of concept for a client, and sometimes as an environment when I&rsquo;m doing presentations.<\/p>\n<p>In the old days, the way I had to do it was either by using the GUI or learn the DCPromo command. But in Windows Server&nbsp;2012, life got so much better. The GUI and Windows PowerShell produce a far better team.<\/p>\n<p>So here we have a blank server. The only thing that has been done is that the static IP address has been configured, and it has been named CONTOSO-DC.<\/p>\n<p>Promoting this to a domain controller by using Windows PowerShell is actually pretty easy. I can do this with the GUI of course, but that would be about five or six pretty pictures, which I can replace with a few lines in Windows PowerShell.<\/p>\n<p>Our first process is to enable the Active Directory Domain Services on the server. In Windows PowerShell, we can just execute this command:<\/p>\n<p style=\"padding-left: 30px\">Install-WindowsFeature AD-Domain-Services &ndash;IncludeManagementTools &ndash;IncludeAllSubFeature<\/p>\n<p>Now I need to show you a really cool feature that was introduced in Windows Server&nbsp;2012&mdash;which is why I love using it more than previous versions. Let&rsquo;s run through the wizard and turn this into a full domain controller in a new domain called&hellip;well&hellip;CONTOSO.LOCAL.<\/p>\n<p>After the domain services are added, you&rsquo;ll see a yellow triangle with an exclamation point near the top of the new Server Manager. Click that, and you&rsquo;ll see a <strong>Post Deployment Configuration<\/strong> option. Click <strong>Promote this server to a domain controller<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0160.1.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0160.1.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>We&rsquo;ll expand this task and select the hyperlink under <strong>Action<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1030.2.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1030.2.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>From this point, we should see some familiar screens. We&rsquo;re going to add the new forest called CONTOSO.LOCAL.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8688.3.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8688.3.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>We&rsquo;re also going to go cutting edge and choose our forest and domain functional level at Windows Server&nbsp;2012. We&rsquo;ve also populated our Directory Services Restore Mode password. And now the most insecure thing ever! Here&rsquo;s the password: <strong><em>Secret321!<\/em><\/strong><\/p>\n<p>There is no previous domain, so of course we&rsquo;ll be skipping by that screen. We&rsquo;ll verify the NETBIOS name for our domain as shown in the following screen.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2337.4.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2337.4.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>And verify our paths. (OK! You in the back! Stop yawning.)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2744.5.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2744.5.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>And now the coolest screen of all in Windows Server&nbsp;2012&mdash;the <strong>Review Options<\/strong> screen:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3580.6.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3580.6.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>The reason for its coolness is the <strong>View Script<\/strong> button in the lower-right. Clicking it shows us the Windows PowerShell script that is about to run.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2728.7.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2728.7.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>What we&rsquo;re going to do now is cancel the wizard and paste this into our Windows PowerShell Console to see what it does. I&rsquo;m looking, and I don&rsquo;t see my password anywhere.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8463.8.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8463.8.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Aha! It&rsquo;s prompting for the password. But I&rsquo;ll bet there is a parameter we can supply the password to. Because the prompt is <strong>SafeModeAdministratorPassword<\/strong>, that would usually be the missing parameter.<\/p>\n<p>I&rsquo;m going to guess that we have to convert this password to a secure string because most commands from Microsoft won&rsquo;t accept a clear text password directly. So we&rsquo;ll drop the following command inside our parameter called <strong>-SafeModeAdministratorPassword<\/strong>:<\/p>\n<p style=\"padding-left: 30px\">(CONVERTTO-SecureString &ldquo;Secret321!&rdquo; &ndash;asplaintext &ndash;force)<\/p>\n<p>So the really cool part with this prebuilt script is that we can easily modify it to have our variables at the top of the script to simply substitute into the command. With it designed in this way, a person with no administrative knowledge could actually spin up their own domain controller in a lab by only to knowing three key details:<\/p>\n<ul>\n<li>New domain name<\/li>\n<li>New NetBIOS name<\/li>\n<li>Default password for Administrator<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\">$Domainname=&rdquo;Contoso.local&rdquo;<\/p>\n<p style=\"padding-left: 30px\">$DomainNetbios=&rdquo;Contoso&rdquo;<\/p>\n<p style=\"padding-left: 30px\">$Password=&rdquo;Secret321!&rdquo;<\/p>\n<p>Now there is, of course, one additional piece to remember. When we promote to a domain controller in a new domain, it will grab the local Administrator password and set that as the default. To ensure our new domain accepts the password defined by the user in our script, we&rsquo;ll need to reset the local Administrator password.<\/p>\n<p>Now I could use the <strong>[ADSI]<\/strong> accelerator for this, but I love the fact I can use legacy solutions to this day in Windows PowerShell:<\/p>\n<p style=\"padding-left: 30px\">NET USER Administrator $Password<\/p>\n<p>Now with all of this in place, we can have a nice little script to spin up a new test domain:<\/p>\n<p style=\"padding-left: 30px\">Param(<\/p>\n<p style=\"padding-left: 30px\">[string]$DomainName=&rsquo;Contoso.local&rsquo;,<\/p>\n<p style=\"padding-left: 30px\">[string]$DomainNETBIOSName=&rsquo;CONTOSO&rsquo;,<\/p>\n<p style=\"padding-left: 30px\">[string]$Password=&rsquo;Secret321!&rsquo;<\/p>\n<p style=\"padding-left: 30px\">)<\/p>\n<p style=\"padding-left: 30px\">Import-module ADDSDeployment<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Add Domain Services to Server<\/p>\n<p style=\"padding-left: 30px\">INSTALL-WindowsFeature AD-Domain-Services &ndash;IncludeManagementTools -IncludeAllSubFeature<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Reset local Administrator password to<\/p>\n<p style=\"padding-left: 30px\"># One defined in Script<\/p>\n<p style=\"padding-left: 30px\">NET USER Administrator $Password<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Install our Shiny new Forest. It&rsquo;s a good place for SQuirreLs to see *&rsquo;s<\/p>\n<p style=\"padding-left: 30px\">#<\/p>\n<p style=\"padding-left: 30px\">Install-ADDSForest &ndash;SkipPreChecks &ndash;CreateDnsDelegation:$False `<\/p>\n<p style=\"padding-left: 30px\">&ndash;DatabasePath &lsquo;C:\\Windows\\NTDS&rsquo; &ndash;DomainMode &lsquo;Win2012&rsquo; `<\/p>\n<p style=\"padding-left: 30px\">&ndash;DomainName $DomainName &ndash;DomainNetbiosname $DomainNETBIOSName `<\/p>\n<p style=\"padding-left: 30px\">&ndash;ForestMode &lsquo;Win2012&rsquo; &ndash;InstallDns:$True &ndash;Logpath &lsquo;C:\\Windows\\NTDS&rsquo; `<\/p>\n<p style=\"padding-left: 30px\">&ndash;NoRebootOnCompletion:$True &ndash;SysvolPath &lsquo;C:\\Windows\\SYSVOL&rsquo; `<\/p>\n<p style=\"padding-left: 30px\">&ndash;SafeModeAdministratorPassword (CONVERTTO-SecureString $Password &ndash;asplaintext &ndash;force) `<\/p>\n<p style=\"padding-left: 30px\">&ndash;force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"># Restart and Get &lsquo;er done<\/p>\n<p style=\"padding-left: 30px\">RESTART-COMPUTER &ndash;force<\/p>\n<p>Tomorrow we&rsquo;ll expand on this domain controller, and we&rsquo;ll work on prepopulating that environment without us doing all the typing!<\/p>\n<p>I invite you to follow the Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Sean Kearney<\/strong>, Honorary Scripting Guy and Windows PowerShell MVP<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Leverage Windows PowerShell in Windows Server&nbsp;2012 to create a new Active Directory forest. &nbsp;Hey, Scripting Guy! I often have to put together demo environments, and I need a new empty Active Directory forest. Is there any way I can do this faster than by using the GUI&hellip;maybe with Windows PowerShell? &mdash;TM &nbsp;Hello TM, Honorary [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,56,3,154,45],"class_list":["post-2651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Leverage Windows PowerShell in Windows Server&nbsp;2012 to create a new Active Directory forest. &nbsp;Hey, Scripting Guy! I often have to put together demo environments, and I need a new empty Active Directory forest. Is there any way I can do this faster than by using the GUI&hellip;maybe with Windows PowerShell? &mdash;TM &nbsp;Hello TM, Honorary [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2651"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2651\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}