theme-sticky-logo-alt

Create a scripted SharePoint 2013 Development Environment Tutorial – Part 1

14 Comments

Introduction

Creating a SharePoint Development Virtual Machine is something you might have to do quite a few times as a Developer. Even if it’s a pretty easy process, on a slow machine it can easily kill 4-5 hours of your day only to install SQL, SharePoint, Visual Studio and all the others tools you might need to get started. What if you could just script it so it’s all done automatically while you go take coffee, chat on SharePoint Community or whatever else you enjoy doing? In this tutorial we will learn how to build a script that we will keep using for as long as you keep developing on SharePoint 2013. The tutorial will be split in a few sections since in order to keep them focused and short, and at the end they will all be published in a downloadable PDF. I strongly encourage you to not only copy the scripts, but actually read the blog posts of why I did them like this and there are some parts where you will need to work as well! This Guide will show you how to install the following:

  • Microsoft SharePoint Server 2013 – August 2013 CU (Also show you how to install future ones)
  • Microsoft SQL Server 2012 + SP1
  • Microsoft Visual Studio 2012 + All the developers tools needed for SP 2013

Optional extra software:

  • Microsoft SharePoint Designer 2013
  • Google Chrome
  • Firefox
  • NotePad++
  • Smtp4dev
  • ULSViewer
  • HNSC Creator

Sections:

  1. Introduction & Prerequisites & Creating the Domain and Service Accounts
  2. Installing software prerequisites + SQL
  3. Installing SharePoint 2013
  4. Installing Visual Studio 2012 and Optional Software
  5. Basic Optimizing and Summary
  6. Advanced Optimizing of the scripts! (You are here)
  7. An eBook Guide of the 6 sections and a video! (19/11/2013)

Prerequisites

  • A Windows Server 2012 Virtual Machine
  • The Virtual Machine should have 2+ Cores (to avoid SharePoint 2013 Installation Error)
  • 1 Private Network Card attached to the virtual machine. Do not add your External card with internet connection right away, I will tell you when you can!
  • All the Binaries and Licenses for the software you want to install.

Creating the Domain and Service Accounts

Now that the Windows Server 2012 Virtual Machine is installed, the first thing we need to do is set the Execution Policy to Unrestricted. So, we will run this command:

Set-ExecutionPolicy unrestricted

Also, you can optionally turn off UAC to avoid annoying prompts on the development machine with this command New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force Then first need to change the PC name to something understandable! So we will run this command (Don’t forget to change the PC Name to whatever you want):

$pcname = "DevMachine1"
Rename-Computer -NewName $pcname -force

Next, we will set our private network card to a static IP. If you don’t, it will give errors later when creating the new forest. We set it to a static IP with this script:

$netadapter = Get-NetAdapter -Name Ethernet
$netadapter | Set-NetIPInterface -Dhcp Disabled
$netadapter | New-NetIPAddress -IPAddress 192.168.110.5 -PrefixLength 24
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses "192.168.110.5"

Afterwards, we will Install the Active Directory Domain Services Role and Management tools, and restart the computer to make sure the NameChange finishes successfully.

Import-Module Servermanager
Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools
Restart-Computer

After the computer restarts, log in with the administrator account and we will finally create the new forest and domain. The Script is the following (make sure you change the “vladdev.local” and “vladdev” for domain you wish to have)

Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012" `
-DomainName "vladdev.local" `
-DomainNetbiosName "VLADDEV" `
-ForestMode "Win2012" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

The computer will now restart, and will ask you to re-login, but now it’s a Domain Controller (You can now add your internet connection for the rest of the tutorial )! We now need to create our SharePoint 2013 Service Accounts. To easily make that scripted, you should download the SharePoint 2013 Service Account Creator tool from CodePlex. When this tutorial was made, the tool was in version 1.5, so if the latest version is not 1.5 make sure you check if anything changed between then and now! What we are also going to do is create a folder on the C drive called “SharePoint” (C:\SharePoint). It’s very important to call it exactly like that because we will hardcode it in PowerShell to allow easier automation. So after we download and extract the tool in C:\SharePoint it should look like this: SharePoint 2013 Development Environment Tutorial We will open PowerShell like an Administrator, and run the following script to create the accounts:

cd c:\SharePoint
.\sp2013serviceaccounts.ps1 -Level high -SPOU "SP Service Accounts" -SQLOU "SQL Service Accounts" -SQLLevel high -OptionalAccounts $true

Then, the script will ask us to input the password for all the service accounts. Since it’s a Development environment, we can give all the accounts the same password, so for example I want it to be “pass@word1” and Press Enter.

Now, the PowerShell script should run fine and the result should be something like this:

And, if you go check out the Active Directory Users and Computers, you should now have two new Organizational Units (OU) for Service Accounts called “SP Service Accounts” and “SQL Service Accounts” with a bunch of users in them

You might ask yourself why we don’t run everything under 1 user, since it’s a development machine… In my opinion a development machine should be as similar to a production one as possible and therefore running your code with only 1 account and many accounts may make you think works perfectly, but will not work in a more secure environment.

Summary of Part 1

In part 1 of the tutorial, we ran a bunch of PowerShell commands, but we can easily create only two scripts with them to make it easier to run afterwards. The first command you will always need to run by hand is “Set-ExecutionPolicy unrestricted” and, you cannot get away from this one. Next, let’s group our commands in three scripts. The first script who will prepare the VM for the Domain Creation.

#Name: preparepc.ps1
#Purpose: Prepares the Virtual Machine for the Domain Creation
Set-ExecutionPolicy unrestricted
#turn off UAC
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
#Set Static IP on Card
$netadapter = Get-NetAdapter -Name Ethernet
$netdapter | Set-NetIPInterface -Dhcp Disabled
$netadapter | New-NetIPAddress -IPAddress 192.168.110.5 -PrefixLength 24
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses "192.168.110.5"
#Change PC Name
$pcname = "DevMachine1"
Rename-Computer -NewName $pcname -force
#Add AD DS Role
Import-Module Servermanager
Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools
Restart-Computer

The second script who will create the domain!

#Name: createdomain.ps1
#Purpose: Creates the new Forest
# Windows PowerShell script for AD DS Deployment
Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012" `
-DomainName "vladdev.local" `
-DomainNetbiosName "VLADDEV" `
-ForestMode "Win2012" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

And the Third Script that Creates the Accounts

#Name: createaccounts.ps1
#Purpose: Creates Service Accounts
cd c:\SharePoint
.\sp2013serviceaccounts.ps1 -Level high -SPOU "SP Service Accounts" -SQLOU "SQL Service Accounts" -SQLLevel high -OptionalAccounts $true

Now that we got them, let’s create those scripts and put them into our C:\SharePoint Folder. It should look something like:

Head over to Next Sction:   Installing software prerequisites + SQL 

Share this post with your followers on twitter:

Leave  a comment and don’t forget to like us on Facebook here and to follow me on Google+ here and on Twitter here  for the latest news and technical articles on SharePoint.  Also, don’t forget to check out SharePoint Community.Net for more great SharePoint Content

Previous Post
SharePoint MVP 2013
Next Post
Create a scripted SharePoint 2013 Development Environment Tutorial – Part 2

14 Comments

  • October 12, 2013 at 12:15 pm

    very good start to this series. I have a uber script myself for my dev rig, interested to see yours

    Reply
  • March 5, 2014 at 9:15 pm
    Rafael Guedes

    Very well written post! Keep up the good work.

    Reply
  • May 30, 2014 at 3:00 am
    Alok

    Thanks for solving my issue, I am looking for this since long.

    Reply
  • June 12, 2014 at 2:27 pm
    Frédéric Aubé

    Thank you for these posts. I never had a SharePoint development environment configured so well!

    Reply
  • August 10, 2014 at 5:14 pm
    Jonas

    Hi,

    You can install SharePoint 2013 on Windows 8 using this tool, you decide if it’s a good fit for you 🙂

    http://www.disruptivei.com/Blogg/Inl%C3%A4gg/6/Install-SharePoint-2013-on-Windows-7-8-8-1

    Thanks,
    Jonas

    Reply
    • August 12, 2014 at 12:17 am

      As you said in the blog post “It is COMPLETELY unsupported by MS and should only be used for a local development/demo machine.”. However, I love the idea and will probably check it out! Thanks for Sharing!

      Reply
  • December 8, 2014 at 2:11 pm
    Vince

    For anyone out there that finds this blog, and had manually created the domain before running the script. Make sure never to name your domain and server the same, it will cause a lot of issues in the follow-up posts. I learned the hard way. Not my brightest moment.

    Reply
  • June 26, 2015 at 2:06 am

    Vlad, Thanks for the awesome series of posts on creating sharepoint dev environment. Keep it UP

    Reply
  • July 17, 2015 at 1:33 am
    SharePoint 2013 Online Training

    As a Newbie, I am constantly exploring Online for articles that can be of assistance to me.Thank you

    Reply
  • March 22, 2018 at 4:45 pm
    Jimbr

    Trying your scripting for SharePoint and the 3rd scrippt above:
    #Purpose: Creates Service Accounts
    cd c:\SharePoint
    .\sp2013serviceaccounts.ps1 -Level high ……

    Does not work because there is no c:\SharePoint directory… I can’t just create it as it is supposed to have content. Did I miss a step or ?

    Reply
  • March 22, 2018 at 4:49 pm
    Jimbr

    sorry – found my error

    Reply

Leave a Reply

15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1