Create a scripted SharePoint 2013 Development Environment Tutorial – Part 1
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:
- Introduction & Prerequisites & Creating the Domain and Service Accounts
- Installing software prerequisites + SQL
- Installing SharePoint 2013
- Installing Visual Studio 2012 and Optional Software
- Basic Optimizing and Summary
- Advanced Optimizing of the scripts! (You are here)
- 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: 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