Neudesic Blogs

Passion for Innovation

PowerShell commands to help configure a development environment

Continuing my PowerShell fetish for another week I thought I’d write about some of the PowerShell commands I have been using to configure my development environments in this article.

The set of commands I run are used to disable a lot of the security features that are great to have in production but do nothing aside from producing headaches in a development environment.  I’ll start with a base installation of Windows Server 2008 R2 Enterprise and then begin to run these scripts.

First we run this command to make sure that we are allowed to run scripts in the PowerShell command window that aren’t signed.

  Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force

Next up is disabling the IE ESC settings.  We do this by updating the registry keys for this property.

  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"

We will also want to disable User Access Control as well so we don’t have to keep remembering to run things as administrator.  Again this is just a registry update.

  Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value "00000000"

Of course we need to disable the shutdown tracker so we don’t have to type “adfs” in a prompt every time Windows is being shut down.  Also a registry change, this time we’re adding a key instead of modifying an existing one but it’s essentially the same process.

  New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT" -Name "Reliability" -Type "RegistryKey"

  New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Reliability" -Name "ShutdownReasonOn" -Value "0" -PropertyType dword

This one is to disable the loopback check.  If you’re not familiar with the problem, it is caused when attempting to authenticate against a site being hosted on the same machine you’re browsing from if the URL is not the same as the computer name.  You’ll be challenged for credentials and no matter what you enter you’ll be prompted 3 times and then denied access.  This is a symptom of a security feature to help prevent certain types of reflection attacks that you probably won’t care about in your development environment so here is the command you can use to turn it off.

  New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Lsa" -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword


To rename my computer to something a little more useful than a randomly generated name I use this command.

  $ComputerName = “MyComputerName”

  $computer = Get-WmiObject Win32_ComputerSystem



I also tend to need my development box to run as a domain controller.  To promote my server to a DC I use the following command.

  $DNSName = “DEV001.NET”

  $NetBiosName = “DEV001”

  $SafeModeAdminPassword = “pass@word1”

  dcpromo /unattend /ReplicaOrNewDomain:Domain /NewDomain:Forest /NewDomainDNSName:$DNSName /DomainNetBiosName:$NetBiosName /InstallDNS:Yes /RebootOnCompletion:No /SafeModeAdminPassword:$SafeModeAdminPassword


So that is all I’ve got for this article.  I hope this was useful for some of you.


Posted: Mar 14 2012, 05:29 by Michael.Thompson | Comments (0) RSS comment feed

Tags: , ,
Categories: General | Portals & Collaboration

A PowerShell Script to Restart Computer and Continue Execution

So originally I had set out to write an article about setting up a SharePoint 2010 development environment.  I know it’s been written about ad nauseam but thought it would be a great way to get my feet wet in the blogging world.  Anyway as usual I got myself distracted so this article is not about building a SharePoint 2010 development environment.  It’s about one piece of that puzzle, specifically a simple pattern to automate the executing, restarting, and continuation of a PowerShell script.

So when I started I had one goal.  I wanted to be able to take a fresh installation of Windows Server 2008 R2 and with one click install and configure all of my development tools.  At the time I knew next to nothing about PowerShell but I was pretty sure it was going to be the correct tool.

The first hurdle I had to get over, and the one this article focuses on, was how to get my PowerShell script to restart the box and then continue where it left off.  Some quick searching got me headed in the correct direction.  Basically you can get PowerShell to write to the registry and by doing so you can get it to add itself to the Windows startup routine.  With some clever passing of parameters you have the ability to get the script to start where it left off.  Here’s a stripped down version of the code:


function Set-NextStep() {


  Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "SystemSetupStep" -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe &C:\Setup.ps1 -Step $global:Step"


function Run-NextStep() {

  switch ($global:Step) {

    1 { Step-1; break; }

    2 { Step-2; break; }

    default { Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "SystemSetupStep" }



function Step-1() {

  Write-Host "This is step 1"




function Step-2() {

  Write-Host "This is step 2"






Ok, so let’s break this thing down.  First line is the $Step parameter.  This allows me to pass a value into the script when I call it from the command line or if I omit the parameter it sets itself to 1.

Next is the function Set-NextStep().  It increments the parameter $Step by 1 and then writes some information to the registry.  Specifically it adds an entry that tells Windows to execute a command on startup.  What is that command?  I’m asking it to start the PowerShell command window and to load my script as well as pass in the parameter $Step which would now be one value greater than when I started.

The Run-NextStep() function is simply a switch statement driven by the value of the parameter $Step.  What I really like about this is how well it documents what is actually going on.  It clearly shows you what steps are going to be executed and in what order.  The default behavior of the switch statement is some cleanup of the registry to remove the command that tells Windows to execute the script on startup.

Then I have two sample functions in there.  Step-1() outputs to the command window and then sets the next step before it restarts the computer.  Step-2 outputs to the command window sets the next step and runs the next step.

And that is that.  A simple little pattern to execute multiple functions in PowerShell over as many reboots as you need.  In the future maybe I’ll post my full blow version of this that actually does build a SharePoint 2010 Development box.



Posted: Mar 07 2012, 04:28 by Michael.Thompson | Comments (0) RSS comment feed

Tags: ,
Categories: General | Portals & Collaboration

Folks still using WSPBuilder even with SharePoint 2010

I learned today that many Visual Studio 2010/SharePoint 2010 solution developers are still using Carsten Keutmann's WSPBuilder tool, despite all the new WSP package, deploy, and debug facilities built into Visual Studio 2010.

I had used WSPBuilder extensively in all my MOSS (SharePoint) 2007 projects but not with any of my 2010 projects. Now come to find out, people like David Stampfli at Microsoft still use WSPBuilder despite all the built-in stuff in 2010!

One word to the wise: there is a separate version of WSP Builder for SharePoint 2010/Visual Studio 2010. It's called WSP Builder Extensions 2010 Beta 1.4 and you get it from here: At first, I made the mistake of downloading the "Recommended Download" (WSP Builder Extension 1.06...) and after installing, I could not find any WSP Builder project templates available in my Visual Studio 2010. Browsing Carsten Keutmann's blog, I noticed that it mentions "Please look on codeplex under Download. It's the last file of the 4 available." After I got the WSP Builder Extensions 2010 Beta 1.4 the templates became available as expected.

Posted: Nov 02 2011, 19:28 by Martin.Cox | Comments (0) RSS comment feed

Categories: Portals & Collaboration





Neudesic Social Media

Follow Neudesic on Twitter Follow Neudesic on Facebook Neudesic Neudesic