다음을 통해 공유


Starting/Stopping your SharePoint 2010 Dev environment with Powershell

SharePoint 2010 introduced the ability to host SharePoint on Windows 7 for development purposes… which is fantastic… no more VM. However, when SharePoint 2010 installs/configures services it configures them to start up automatically (or at minimum allows “Automatic” services to start “Manual” services). While this is great for my server… its not so great for my laptop with 4GB of memory. I can’t speak for you… but I’m not writing code 100% of the time… and that 2GB of memory can be used for other things when I’m not.

So, attached is a Powershell script that can be used to start/stop the services whenever you’d like. I had a few requirements for myself when writing this script:

  1. It must start and stop the services in a specific order. For example, it would be stupid to start IIS without having SQL running.
  2. It must wait for a service to finish starting before moving on to the next service. Same reasons as above, but this rules out the “SC” command-line option since it isn’t synchronous.
  3. It should know what I want to do without asking me. For example, if the services are stopped, it should start them. If they’re started, it should stop them. No questions asked.
  4. It should manage the startup type too. For example, in order to start a service it can’t be “Disabled”, yet I want them to be “disabled” unless I start them… so the script must control startup type.
  5. It should be flexible for other service stacks. For example, it should be reusable for perhaps a secondary IIS application which may also require SQL but not SharePoint.

Here’s a visual of the effects of the script on memory utilization:

Before running the script to start the services… After running the script to start the services and hitting my web app and CA… After running the script again to stop the services…
image image image (I’m willing to accept that starting SharePoint pushed something else to virtual memory, hence the difference from start).

 

 

 

The one note is that the script requires a UAC jump in order to manage the services… you have to select “Run as administrator” for it to work. This would be required on any UAC enabled system, so I don’t consider it much of a drawback. That being said, the fact that .ps1 extensions do not automatically have the “Run as administrator” option can be difficult, I’ve also included a registry export to enable this option. Just double-click the .reg file, and “Run as administrator” will be enabled for all Powershell scripts.

This is my first Powershell script, so feel free to leave a comment pointing out areas I could have done this better… :)

Flip SharePoint.zip

Comments

  • Anonymous
    December 07, 2011
    Genius, absolutely genius. Thanks for the effort!

  • Anonymous
    March 01, 2013
    The comment has been removed