theme-sticky-logo-alt

Create a scripted SharePoint 2013 Development Environment Tutorial – Part 2

7 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!

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)

Installing software prerequisites

We will do everything under the assumption that even if this virtual machine is installed with an internet connection, we would be able to install all the next ones completely offline. First thing that we need is the sxs folder from a Windows Server 2012 ISO File. We will need it to install .Net Framework 3.5

SharePoint 2013 Development Environment Tutorial

Copy the whole sxs folder to C:\SharePoint.

Now, run PowerShell as an Administrator and run the following command to install .Net Framework 3.5

Import-Module ServerManager
DISM.exe /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:"C:\SharePoint\sxs"

Next, you will probably connect to this Virtual machine with Remote Desktop, so let’s enable it!

(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)
(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0)

For Remote Desktop and SQL to work properly without too much hassle, we will also disable the firewall!

netsh advfirewall set allprofiles state off

Next, let’s disable IE Enhanced Security…. As it’s really annoying.

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0
Rundll32 iesetup.dll, IEHardenLMSettings,1,True
Rundll32 iesetup.dll, IEHardenUser,1,True
Rundll32 iesetup.dll, IEHardenAdmin,1,True
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}")
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
}
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}")
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
}
Remove-ItemProperty "HKCU:\SOFTWARE\Microsoft\Internet Explorer\Main" "First Home Page" -ErrorAction SilentlyContinue

Before the next reboot is required, we will add the SQL_Admin and SP_Admin accounts to the local administrator group… make sure you change the domain info!

$pcname = hostname
Set-ADGroup -Add:@{'Member'="CN=Sp_Admin,OU=SP Service Accounts,DC=vladdev,DC=local", "CN=Sql_Admin,OU=SQL Service Accounts,DC=vladdev,DC=local"} -Identity:"CN=Domain Admins,CN=Users,DC=vladdev,DC=local" -Server:"$pcname.vladdev.local"

We might want to install / test some client software in the future, so let’s add the Desktop Experience Feature!

Add-WindowsFeature Desktop-Experience
Restart-Computer

After the computer restarts, we will log in with the SQL_Admin account!

Installing SQL Server 2012

Everything until now was pretty straightforward and easy, especially since I gave you most of the scripts. However, installing SQL Server 2012 is not as easy and it will require some input from you! To Begin with, insert the SQL 2012 ISO (with SP1 Preferably) in the virtual machine, and let’s create a folder in C:\SharePoint called “SQLBinaries” and copy all the SQL Binaries inside it!

We won’t open Powershell right away… instead of me giving you all the script and configuration file which risks not working on your computer, I will show you step by step how to do it yourself! First, start setup.exe! Go in the Installation Tab and click on New SQL Server Instance. I won’t include every Screenshot, only those where you need to modify something.

The Minimum you need for the following screen is “Database Engine” and “Management Tools – Complete”

Do not Enter an Instance Name… It’s a Dev Environment!

Enter the Service Accounts we created in the earlier step and their good passwords!

Configure SQL in Mixed Mode and add SQL_Admin, SP_Admin and the “Domain Admins” group to the SQL Server Administrators.

And now we stop at this step! Do not click install!

You can see that on the bottom, we have a “Configuration File Path”. That’s the Configuration File we need, so go at the path there and copy the “ConfigurationFile.ini” file in C:\SharePoint\SQLBinaries . You can now cancel the Installation Wizard!

Now that we have everything configured in there, let’s see how we do it with PowerShell for the next times! Just fill the info for the following script!

cd c:\SharePoint
.\SQLBinaries\Setup.exe /ConfigurationFile=.\SQLBinaries\ConfigurationFile.INI /Q /Action=Install /IAcceptSQLServerLicenseTerms /SQLSVCPASSWORD=pass@word1 /AGTSVCPASSWORD=pass@word1 /sapwd=pass@word1

If you go in the Start Menu, you should now have a bunch of SQL tools. You can open the Management Studio if you want to start checking your SQL Configuration.

SQL is now setup!

Summary

In Part 2 of this tutorial, we enabled and disabled a bunch of Windows Features in order to make it easy for us to develop afterwards and to make sure everything installs smoothly. Furthermore we created the SQL Configuration file we will use in the future as well as install SQL. We only have two scripts we will use for future installations:

Script 1 that Enables all the features and installs .Net Framework 3.5

#Name: prereqsandfeatures.ps1
#Purpose: Installs Prerequisite Software and Features
#Disable Firewall
netsh advfirewall set allprofiles state off
#Disable IE Enhanced Security
Write-Host -ForegroundColor White " - Disabling IE Enhanced Security..."
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name isinstalled -Value 0
Rundll32 iesetup.dll, IEHardenLMSettings,1,True
Rundll32 iesetup.dll, IEHardenUser,1,True
Rundll32 iesetup.dll, IEHardenAdmin,1,True
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}")
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
}
If (Test-Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}")
{
Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
}
Remove-ItemProperty "HKCU:\SOFTWARE\Microsoft\Internet Explorer\Main" "First Home Page" -ErrorAction SilentlyContinue
#Enable Remote Desktop
(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)
(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0)
#Add .Net FrameWork
Import-Module ServerManager
DISM.exe /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:"C:\SharePoint\sxs"
#add SPAdmin and SQL Admin to Local(Domain) Administrators
$pcname = hostname
Set-ADGroup -Add:@{'Member'="CN=Sp_Admin,OU=SP Service Accounts,DC=vladdev,DC=local", "CN=Sql_Admin,OU=SQL Service Accounts,DC=vladdev,DC=local"} -Identity:"CN=Domain Admins,CN=Users,DC=vladdev,DC=local" -Server:"$pcname.vladdev.local"
#Enable Desktop Experience
Add-WindowsFeature Desktop-Experience
Restart-Computer

Script #2 which installs SQL!

#Name: installsql.ps1
#Purpose: Installs SQL
cd c:\SharePoint
.\SQLBinaries\Setup.exe /ConfigurationFile=.\SQLBinaries\ConfigurationFile.INI /Q /Action=Install /IAcceptSQLServerLicenseTerms /SQLSVCPASSWORD=pass@word1 /AGTSVCPASSWORD=pass@word1 /sapwd=pass@word1
shutdown -l

We can now log on with SP_Admin and head over to Part 3: Installing SharePoint 2013 

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
Create a scripted SharePoint 2013 Development Environment Tutorial – Part 1
Next Post
SharePoint 2010 RTM Language Packs are gone! What do I do now?

7 Comments

  • December 19, 2013 at 10:33 pm
    Joe

    I got an error “The /UIMode setting cannot be used in conjunction with /Q or /QS” running set.xex by script. It is SQL2012 with SP1 on Windows 2012 r2. Find a link http://social.msdn.microsoft.com/Forums/sqlserver/en-US/368211a0-8af3-4255-992a-c5e7cdc5b637/sql-installation-with-configurationfileini?forum=sqlsetupandupgrade
    but it does not help. Any idea what I should do

    Reply
    • February 6, 2014 at 1:11 pm

      Can you try to go to the config file and comment out or delete the UIMode line? Tell me how it goes!

      Reply
  • January 23, 2014 at 5:45 pm
    Joe

    I got following error when installing sql. Any idea how to fix it

    cd c:\SharePoint
    .\SQLBinaries\Setup.exe /ConfigurationFile=.\SQLBinaries\ConfigurationFile.INI /Q /Action=Install /IAcceptSQLServerLicenseTerms /SQLSVCPASSWORD=!QAZ2wsx /AGTSVCPASSWORD=!QAZ2wsx /sapwd=!QAZ2wsx

    The following error occurred:
    The /UIMode setting cannot be used in conjunction with /Q or /QS.

    Error result: -2054422500
    Result facility code: 1420
    Result error code: 28

    Reply
    • February 6, 2014 at 1:10 pm

      Can you try to go to the config file and comment out or delete the UIMode line? Tell me how it goes!

      Reply
  • June 14, 2014 at 10:32 am
    Americo

    Yes!, commented out UIMode-line and it worked perfect!!!

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

    Great blog. If I may make a suggestion on the SQL install script, that I made for myself.

    from the microsoft web site “Enable or Disable a Server Network Protocol using Powershell” I added the following to the installsql.ps1

    #Name: installsql.ps1
    #Purpose: Installs SQL
    cd c:\SharePoint
    .\SQLBinaries\Setup.exe /ConfigurationFile=.\SQLBinaries\ConfigurationFile.INI /Q /Action=Install /IAcceptSQLServerLicenseTerms /SQLSVCPASSWORD=pass@word1 /AGTSVCPASSWORD=pass@word1 /sapwd=pass@word1
    shutdown -l

    $smo = ‘Microsoft.SqlServer.Management.Smo.’
    $wmi = new-object ($smo + ‘Wmi.ManagedComputer’).

    # List the object properties, including the instance names.
    $Wmi

    # Enable the TCP protocol on the default instance.
    $uri = “ManagedComputer[@Name=”]/ ServerInstance[@Name=’MSSQLSERVER’]/ServerProtocol[@Name=’Tcp’]”
    $Tcp = $wmi.GetSmoObject($uri)
    $Tcp.IsEnabled = $true
    $Tcp.Alter()
    $Tcp

    # Enable the named pipes protocol for the default instance.
    $uri = “ManagedComputer[@Name='” + (get-item env:\computername).Value + “‘]/ServerInstance[@Name=’MSSQLSERVER’]/ServerProtocol[@Name=’Tcp’]”
    $Np = $wmi.GetSmoObject($uri)
    $Np.IsEnabled = $true
    $Np.Alter()
    $Np

    # Get a reference to the ManagedComputer class.
    $sqlServer = ‘SQLSERVER:\SQL\’ + (get-item env:\computername).Value
    CD $sqlServer
    $Wmi = (get-item .).ManagedComputer
    # Get a reference to the default instance of the Database Engine.
    $DfltInstance = $Wmi.Services[‘MSSQLSERVER’]
    # Display the state of the service.
    $DfltInstance
    # Stop the service.
    $DfltInstance.Stop();
    # Wait until the service has time to stop.
    # Refresh the cache.
    $DfltInstance.Refresh();
    # Display the state of the service.
    $DfltInstance
    # Start the service again.
    $DfltInstance.Start();
    # Wait until the service has time to start.
    # Refresh the cache and display the state of the service.
    $DfltInstance.Refresh(); $DfltInstance

    Reply
  • January 7, 2017 at 12:22 pm
    cynthia28

    I get the following error on this

    $pcname = hostname
    Set-ADGroup -Add:@{‘Member’=”CN=Sp_Admin,OU=SP Service Accounts,DC=vladdev,DC=local”, “CN=Sql_Admin,OU=SQL Ser

    Set-ADGroup : Unable to contact the server. This may be because this server does not
    exist, it is currently down, or it does not have the Active Directory Web Services
    running.
    At line:2 char:1
    + Set-ADGroup -Add:@{‘Member’=”CN=Sp_Admin,OU=SP Service Accounts,DC=cjmdev,DC=loc

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (CN=Domain Admin…cjmdev,DC=loca
    l:ADGroup) [Set-ADGroup], ADServerDownException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Mana
    gement.Commands.SetADGroup

    Reply

Leave a Reply

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