Browsed by
Tag: Helpful Admin Tips

PowerShell Script: SharePoint Farm Creation

PowerShell Script: SharePoint Farm Creation

For a long time I have been meaning to rewrite the PowerShell script that I have been using to do my SharePoint farm creation and just haven’t gotten around to completing the necessary effort to make it all that I want it to be. I have leveraged the work of others, borrowing a piece here and a snippet there but to honest I haven’t been satisfied.

What I really wanted was a script that I can use in my consulting practice as a normalized practice of how a farm should be deployed as well as a script that I could use in the highly repetitive process of doing ITPro dev work. I wanted something that was flexible enough to use for client installs, but repeatable enough that I could use it in my dozens of farm builds that I do in my spare time for troubleshooting and fun.

Here are the key points of what I did differently with this script:

  1. use temporary variables that can be accepted or overridden at the PowerShell command-line when the script is called
  2. validate if the pieces have been implemented correctly & gives information about what piece failed, not just throwing the ugly PowerShell errors that we are used to seeing
  3. validate that you are using PowerShell running as Administrator to ensure that you won’t fail for that silly reason
  4. pulls the system & domain variables rather than having to set those parameters manually

I am happy to report that I was able to accomplish all of these things in my script and am happy to offer it up for others to use if you see fit. I highly recommend that you consider using the PowerShell profile that I laid out in my previous article “How to: Automatically log your PowerShell session everytime” so that you can, among other things, capture the output of building your farm.

There are very few people who can honestly say that they created their PowerShell scripts completely from scratch, and I am certainly not among them. Credit is due for snippets & reference to Shannon Bray, Gary LaPointe, Brian Lalancette, Todd Klindt, & I’m sure others. Special appreciation to Evan Riser for helping me QA this script. 

One last thing to note about this script… it does just what it says it does. It creates a SharePoint farm.  This is not an all inclusive build your farm & configure every setting script. If you are looking for the all inclusive, über build & configure script please go visit Brian’s codeplex project: AutoSPInstaller. There is no need for anyone to recreate the amazing work that he has done. 

The reason I create this scripts like this is that I prefer to break my scripts down into pieces and keep them highly modular. This is partly because I consult on such a wide variety of projects that it makes my life easier to be able to deploy pieces at a time using different scripts. It also could be that I am a neurotic, lunatic control freak who is a bit over obsessed with developing in PowerShell for fun.  Hopefully it’s more the first thing than the second thing… 🙂

I will continue to publish the scripts that I find useful here in the hopes that it helps someone else along the way. You can find my SharePoint Farm Creation PowerShell script here on my SkyDrive.

Updated PowerShell Profiles Creation Script

Updated PowerShell Profiles Creation Script



While enjoying Doug Hemminger’s presentation at the SharePoSH meeting tonight I realized that I hadn’t published an update to my How to: Automatically log your PowerShell session every time post, even though I had fixed some issues with the script more than 2 months ago. FYI, I still blame Todd Klindt for prompting me to write this thing in the first place by introducing me to start-transcript…

I updated the version of code in the previous post from v1.8 to v1.14 without posting about it, however the output formatting was poor.

The major changes from v1.8 to v1.15 are:

1.) Proper formatting of screen outputs
2.) Added PowerShell Active Directory modules
3.) Outputting a validated list of snap-ins & modules that are actually loaded instead of just printing on screen that the SharePoint module loaded even when it hadn’t
4.) Validation that the user is running in the context of an Administrator
5.) Removed unnecessary code & added proper commenting inline

You can find the updated code at on SkyDrive here.

How to: Activate Desktop Experience in Windows Server 2012

How to: Activate Desktop Experience in Windows Server 2012

I ran into an issue where I needed to active that Desktop Experience in on Windows Server 2012 and found that it was not in the same place that I was expecting it to be from previous versions. Figured that this might help some people.

Desktop Experience is required to be running if you are going to utilize OneNote, which when working in a demo server environment can be very useful. There are some DLLs that are not accessible unless you are running the Desktop Experience that are critical to applications like Snagit & Camtasia.

Wizard Driven:

To active the Desktop Experience go Server Manager | Local Server | Manage | Add Roles & Features


Once in the wizard under Features drill into the User Interfaces and Infrastructure and select Desktop Experience. This will active the Ink and Handwriting Services & Media Foundation features as well.


After installation the server requires a reboot to complete and will make the features active for accessing.


From a PowerShell prompt running as Administrator use the following command:


During execution you will see the following:


Once complete you will be notified that you need to reboot the server:



 notepad active Desktop Experince script

How to: Automatically log your PowerShell session every time

How to: Automatically log your PowerShell session every time


At SharePoint Saturday New Hampshire I sat in a packed room and listened as Todd Klindt showed everyone how to install SharePoint 2013 without screwing it up (too badly). The big take away for me was this command that I had not heard about before called start-transcript. The power of start-transcript is that it is able to write everything that you do in a PowerShell session to a log file that you can review later. Todd demo’ed how he throws this every time he opens PowerShell and has found it to be invaluable.

The main reason that I had not heard of start-transcipt before is that I live in PowerShell ISE and rarely (if ever) go into plain ol’ PowerShell, and sadly start-transcript is not supported in PowerShell ISE. DAMN YOU POWERSHELL GODS FOR TEASING ME SO!!!!

The Use Case

The problem that this solves in my view is:

  1. I spend a ton of time tweaking away at some code on a SharePoint server, get it right and then inadvertently close the PowerShell window. It’s just GONE.
  2. Opening and closing PowerShell windows and trying to remember what I manually typed 2 hours ago to fix a problem that got reintroduced after redeploying code.
  3. Needing a way to review who made changes to the serverenvironment and see what they actually did.

The more I thought about it the more the more I liked the ability to log everything that is done in PowerShell on a server, but the issue that I had was that it was something that the person opening PowerShell had to remember to do every time they opened a window.

I started thinking about using PowerShell profiles to implement this for every user. In my experience I have seen profiles used infrequently, but in a couple of the scenarios they have been deployed via AD Group Policy. However if you are working in an environment that you don’t have access to create GPOs or you are working in a development environment and developing GPOs just isn’t your thing what do you do?

The Problem

The task at hand was two-fold:

  1. Auto deploy a PowerShell Profile for SharePoint Admins that would be lightweight, contain the start-transcript function to start automatically, assist in auditing, and be Server Administrator deployable
  2. Figure out if start-transcript like functionality was available for the native PowerShell ISE

The Solution

The solution that I came up with was to leverage the All Users Startup option in Windows to launch a script that would check to see if the folder that holds the PowerShell profile scripts exists. If it exists, the script terminates and all is well. This happens on every interactive login, but takes only a second. If the folder does not exist, the will kick off a creation of the scripts based upon a preset profile definition that includes the targeting & naming of the logs, starting the transcript, and loading the SharePoint module. The profile definition can be completely customized making this a viable approach for admins of other technologies, not just SharePoint.

For PowerShell this is great because it works out perfectly as built. PowerShell ISE on the other hand is still a thorn in our sides. The Scripting Guys, aka Ed Wilson and Craig Liebendorfer, wrote a terrific function that allows you to log the output pane in PowerShell ISE v1 & 2. Sadly this is not working in PowerShell v3 since there is no output pane. Leveraging that we can get part of the functionality in ISE that we get in the command-line version.

Behind the code

The solution that I came up with is in the form of a single PowerShell script that builds the following:

  • 2 folders (at the Root of C:)
    • c:PowerShellLogs will house all of the transcripts
    • c:PowerShellScripts will be the home for the scripts used to build the profiles and will be the default starting location when PowerShell opens. This way you can put all of the scripts you want to call in one place for all users and they can launch them easily.
  • check-profiles.lnk (in the All Users Start Menu Startup folder)
    • This shortcut points to a batch file in the C:PowerShellScripts folder called check-profiles.bat
  • check-profiles.bat (in c:PowerShellScripts)
    • This batch file launches the check-profiles.ps1
  • check-profiles.ps1 (in c:PowerShellScripts)
    • This PowerShell script checks to see if the user has a WindowsPowerShell folder in their My Documents folder. If it finds the folder, the script terminates. If it doesn’t find the folder it launches the create-profiles.ps1 script
  • create-profiles.ps1 (in c:PowerShellScripts)
    • This PowerShell Script creates the profiles for both PowerShell & PowerShell ISE.

Here is what I put in the PowerShell profile:

  • Set the location for PowerShell to start in to C:PowerShellScripts
  • Display a message about needing to Run as Administrator to effect changes
  • Set the path for logging the session to C:PowerShellLogs
  • Set the log name using the user context and date time stamp
  • Start the transcript
  • Display a message about waiting for the SharePoint snap-ins to load
  • Load the SharePoint snap-ins
  • Display a message that loading the SharePoint snap-in is complete and lets you know who you are running PowerShell as

Here is what I put in the PowerShell ISE profile:

  • Set the location for PowerShell to start in to C:PowerShellScripts
  • Display a message about needing to Run as Administrator to effect changes
  • Set the path for logging the session to C:PowerShellLogs
  • Load a function to set the log name using the user context and date time stamp
  • Load the function for Output-ISETranscript (the Scripting Guys code)
  • Display a message about waiting for the SharePoint snap-ins to load
  • Load the SharePoint snap-ins
  • Display a message that loading the SharePoint snap-in is complete and lets you know who you are running PowerShell as


While its may not be the perfect solution for PowerShell ISE that I was looking for when I set out, at the end of the day with this code I now have the ability to automatically log everything done in command line PowerShell.

Thanks to Todd Klindt, Evan Riser, Mark Rackley, and Dan Holme for talking through these use cases, reviewing some of the code, and taking differing view points on this to validate that it is a reasonable approach or not. I love being a part of a community where bouncing ideas and solutions off of peers is so easy and open.

You can find the code here:

powershell notepad

Hopefully this code will be useful to you in your day to day world.

How to: Create a OneNote help file out of a PowerShell Module

How to: Create a OneNote help file out of a PowerShell Module

Being an ITPro in the current day and age I write a decent amount of PowerShell. Since I am not always on a server that has the SharePoint PowerShell modules installed most of my time on TechNet is spent basically reading the help files of specific modules to validate syntax, flags or review examples. This can become a bit of a pain after a while so I thought it would be nice to have a OneNote notebook on my SkyDrive that I could sync to my laptops or access in the cloud where I could search more easily and have all of my cmdlets at my fingertips.

Here is how I accomplished this:

Select the module. For this example I used the Microsoft.SharePoint.PowerShell module, however this will work with any PowerShell module.

Run the following command to get an output of the cmdlets in the module:


Opening in Excel will give you the best opportunity to grab what you need. Column K in this particular output will list all of the cmdlets names.


Grab just that column and copy it to a text file called “cmdlets.csv”.

Next use the following PowerShell command to create an ANSI output file for each of the help files in the module.


For this module it created 771 individual text files. Using the OneNote 2010 Text Importer from John Guin I was able to create a single OneNote file that contains all of the help for the entire SharePoint 2013 PowerShell module that is now searchable in a faster and easier way. One caveat, I had to use OneNote 2010 for the importer to work properly.

Not sure if this will be helpful for anyone else, but I use it all the time when writing PowerShell Code.


I will endeavor to keep this up to date, but since I just explained how to accomplish this, if I slip up you can perform the actions yourself.

You can get download the notebook here:

notepad  get cmdlets in the module script

notepad  create ANSI output file for each of the help files in the module script

Hooray, it’s a book!: “Developing Business Intelligence Apps for SharePoint”

Hooray, it’s a book!: “Developing Business Intelligence Apps for SharePoint”


Over the past year I have been spending my night’s & weekends working on a book with my co-author, Dave Feldman, and I am proud to say that we have completed our draft of “Developing Business Intelligence Apps for SharePoint”

Through the book you will learn to create dynamic Business Intelligence solutions for SharePoint, using Microsoft Visual Studio LightSwitch, SQL Server 2012, and other tools and technologies. This hands-on book shows you how to create data-rich BI applications with SharePoint faster and with more capabilities than previously possible. You’ll learn the entire process, from high-level concepts, to low-code development and deployment, to setup and configuration.

  • Quickly build a robust schema and applications with Visual Studio LightSwitch
  • Leverage PowerPivot v2 to build a business intelligence semantic model
  • Create reports with Excel Services, Report Builder, and Power View

The happy thing about our book is that we saw the CSOM model of SharePoint 2013 coming down the road and architected our solutions in the book so that they are relevant to both the 2010 & 2013 platforms (and hopefully many versions of SharePoint to come).

The book is available for pre-order on Amazon now and will be available via O’Reilly Early Release.   Dave & I will be at the SharePoint Conference in Las Vegas where O’Reilly will have a form of the book available (not quite sure if it will be a few chapters or what at that point, but there will be something!). 

I will say that Dave & I were warned by Andrew Connell & Scot Hillier when we started talking about writing this book that taking on a book project is much like having a child.  9+ months of long uncomfortable sleepless nights to give birth to something that you hope goes on to do good things in this world (I am paraphrasing a bit here… basically they both said it was going to suck something awful, but we would be happy when it was all over).  Well gents, you were right on all counts.  The fun part is that while I have 2 kids and sort of had an idea of what something like that was going to be like, Dave’s wife is pregnant with their first child and is due this SUNDAY.  Needless to say, we are glad to be done before Baby “Cookie Monster” Feldman arrives. smile

250 USB drives to load? WHERE IS MY POWERSHELL CAPE???

250 USB drives to load? WHERE IS MY POWERSHELL CAPE???

In preparation for SharePoint Saturday New Hampshire I had to load 250 USB drives with sponsor’s digital collateral. The fun last evening was getting all of the little buggers out of their individual boxes and sealed plastic wrappers in order to make loading them a bit faster.

Today I ran out to Best Buy and purchased a pair of Belkin 7-Port USB 2.0 Powered Hubs and then sat down to “borrow” some PowerShell commands from someone on the interwebs. Sadly, I did not find a quick pre-canned script that would let me loop through my USB sticks and load them with the data. Here is what I needed my script to do:

1.) Change the name of the USB Drive to “SPSNH 2012”
2.) Copy the files and folders from the location on my hard drive to the USB Drives
3.) With a single trigger, perform the above functions on all drives inserted in the machine

In order to accomplish this I created a drivelist.txt file. Very simple text file with the list of drive letters that I were assigned to the drives when inserted. One key tip here is to make sure that there are no extraneous carriage returns after the final drive letter (this will cause an error later). The contents of the text file look like this:


Next I created a PowerShell script that utilized the WmiObject, WmiInstance & Item command-lets and threw in a foreach loop. The script looked like this:


Using this script, 2 computers & the 2 Belkin hubs I was able to load all almost 100meg on to 250 drives in just under 2 hours with distractions. Not too shabby.

I also created a second script for USB drives that are larger than 4GB that will reformat them as NTFS (or whatever format you choose) so that you can load larger files onto them, then rename the drive & copy the files in. Here is what that script looks like:


Hopefully this will be useful for others in the future. I would not want to be loading these things up without some form of script to assist. Below you can find a plain text version of each of these scripts that you can download and use yourself.

notepad USB Drive rename & copy script (FAT32)

notepad USB Drive format, rename & copy script (NTFS)

SharePoint Saturday New Hampshire is upon us!

SharePoint Saturday New Hampshire is upon us!


With only 3 days to the big event things are rapidly coming together.  The bags, speaker gifts, t-shirts, buttons, digital collateral, prizes and jump drives are all here and ready for Saturday.  I am excited for my presentation “ITPro’s taking the SharePoint 2013 “red pill” will be a ton of fun to present and should be informational as well. 

More than anything I am excited that my co-organizers and I have been able to assemble an amazing cast of speakers to come out to New Hampshire and talk about SharePoint on their own time.  We have speakers coming from Texas, Iowa, Indiana, Washington DC, and all of the New England states to share their expertise with our attendees for free. Being a regular speaker at SharePoint Saturdays for the past year and a half I take for granted all of the hard work that goes into these events and all of the people who give freely of their weekends to come out and speak at these events; it could partly be, as my colleague Mike Gilronan likes to tell people, because “Wherever there are two or more people asking about SharePoint, Jason feels obligated to show up and talk”.

I have really enjoyed helping to put this event together and am excited to see our efforts come to fruition.  If you are in the New England area and want to learn about SharePoint, please find your way up to Southern New Hampshire University on Saturday.  You won’t regret it!

To learn more and register to attend this FREE SharePoint training please visit

How to: Run PowerShell ISE as Administrator under alternate credentials

How to: Run PowerShell ISE as Administrator under alternate credentials

Coming from a security focused AD background I prefer to have the Managed Service Accounts OU locked down with a GPO restricting interactive logon to a server. This helps avoid service accounts becoming compromised and being taken advantage of in attacks.

Having an ISE is especially helpful when you are doing SharePoint work on the farm and while I am a big fan of PowerShell, running straight at the command line is often a pain. Rather than installing one of the terrific third party solutions out there for an Integrated Shell Environment I try to only install the PowerShell ISE.

As we know, there are something that you cannot do unless you are running in the context of the Farm Administrator account. There is code out there that will let you elevate your PowerShell script and run in the context of a different user, but I really wanted to be able to open PowerShell ISE as the farm account so that I can run parts of a script at a time, or rerun specific lines.

Here is the code that I compiled that allows me to launch PowerShell ISE as the Farm Admin account:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

# Farm account name
$farmAccountname =

# Load the Farm Account Creds
$cred = Get-Credential

# Create a new process with UAC elevation S
$PsHomepowershell.exe -Credential $cred -ArgumentList “-Command Start-Process $PSHOMEpowershell_ise.exe -Verb Runas -Wait

Once your PowerShell ISE window is launched you can run the following code to validate that you are running as the user that you are expecting:


Great you learned some more neato PowerShell, but why do I need to use a PowerShell command for this?

You may be asking why wouldn’t I just do a simple “SHIFT+Right Click” and “Run as different user” rather than resorting to a PowerShell solution. The answer is that doing that does not give you the runAs Administrator privileges that we need to do so many of SharePoint’s PowerShell Functions.

Smarty Pants.

powershell PowerShell launch code

notepad Text launch code

powershell User Context validation code

How to disable Shutdown Event Tracker in Windows Server 2008 R2

How to disable Shutdown Event Tracker in Windows Server 2008 R2

Scenario: You have people in your office, you are in the middle of work in 2 different Dev VMs plus Visual Studio on your host or you are working on several servers plus your local Dev VM while writing admin scripts (making this viable for Admin and Dev types alike).  Time for a reboot of your Dev VM so you click on reboot and flip back to your other work and figure you will check back in 10 minutes once it has had time to reboot.  An hour goes by and you are finally rearing to go on the Dev VM so you flip back to it only to find this screen:


Anyone else want to throw a virtual rock at the virtual screen at that point?

I am in the middle of building out 5 new VMs for my lab and always find having to enter a reason for rebooting to be painful, so I FINALLY decided to do something about it. 

There are a number of articles out there on how to do this, but many of them are out of date.  I tried every one of them and this was the one that I found that works every time:

How to enable and disable Shutdown Event Tracker

  1. Open gpedit.msc

  2. Go to Computer Configuration | Administrative Templates | System

  3. Set “Display Shutdown Event Tracker” to Disabled


A reboot is not required for this to take effect.  You set a Group Policy if you are in a domain or multi-machine situation, but for standalone systems, this works just fine.

CAVEAT: I highly recommend this only be used in development/test VMs.  This makes it so there is no safety net if someone accidentally clicks restart or shutdown instead of logoff. 

I am big on giving credit to those who I find information from, but in this case there were so many different options that I lost track of who I got this lead from, so thank you to the unnamed tipster for this lead.