Monday, 28 June 2010

Add SharePoint farm solution and bulk activate feature using PowerShell

There are two parts to this PowerShell script – the first part is fairly straightforward as it simply adds and installs a solution file into the farm. I have added a line to the end of the script to wait until the solution has fully deployed before continuing:

#Set up Web Application variable
#Only needed if solution contains Web Application scoped resources
$webApp = Get-SPWebApplication -Identity http://portal

#Add solution file to the farm
$solution = Add-SPSolution -LiteralPath "C:\Install\Solution.wsp"

#Deploy solution
#Add -WebApplication $webApp to the line below if solution contains Web Application scoped resources
Install-SPSolution $solution -Force -GACDeployment

#Wait for solution to be deployed
do {Start-Sleep -s 1} while ($solution.Deployed -eq $false)

If you have multiple solution files to deploy, then it is worth checking out this script from Gary Lapointe, which enables you to install and deploy solution files in bulk using an XML configuration file.

The second part of the script activates a site or site collection feature, which is also pretty standard, except that I have provided four scenarios:

  • Activate site scoped feature in one site collection

$site = Get-SPSite http://portal
Enable-SPFeature -Identity "FeatureName" -Url $site.Url

  • Activate site scoped feature for all site collections in a Web Application

$webApp = Get-SPWebApplication -Identity http://portal
$webApp | Get-SPSite -limit all | ForEach-Object {Enable-SPFeature -Identity "FeatureName" -Url $_.Url}

  • Activate web scoped feature in one site

$web = Get-SPWeb http://portal
Enable-SPFeature -Identity "FeatureName" -Url $web.Url

  • Activate web scoped feature for all sites in a site collection

$site = Get-SPSite http://portal
$site | Get-SPWeb -limit all | ForEach-Object {Enable-SPFeature -Identity "FeatureName" -Url $_.Url}


  1. Hello,
    Thank for sharing all these articles...
    I have a question about an error occurred when executing enable-spfeature for a feature with a event receiver attached: "Enable-SPFeature : Failed to load receiver assembly... ..System.IO.FileNotFoundExeception...". I make the build again without attached event receiver and this error disappear. What is strange is the fact that I can enable the feature from web without problems (with the event receiver)

    1. Did you ever solve this? I am having the same issue and would like to see if you were able to fix it and how.

  2. Thanks! Is there a way to configure the parameters that my feature needs to connect to a external server? It is a form in the configuration of the site and is empty in every new site, i have a lot of sites. Im glad for your help.

  3. Great stuff dude!
    I used the bulk activation of web scoped features and added to a complete deployment script. Funny thing is, that the server memory fills up to 1,5GB per web scoped feature that is activated. And I activate several, so you can imagine I'm having performance issues. :)
    Any thoughts on how to clear memory after each run of activating a web scoped feature without killing the powershell.exe process

  4. Hi Mark - Are you disposing of the web object after activating features?

  5. It sensual massage in london not simply relaxes your head, legs, arms,
    and elbows as well.

  6. Thanks regarding delivering this type of awesome post
    شركة طيور الجنة افضل شركة تنظيف بالدمام شركة متخصصة فى تنظيف المنازل بالدمام والخبر حيث لدينا طرق خاصة عن باقى شركات التنظيف وعندنا افضل عمال التنظيف حيث انهم متخصصون فى اعمال النظافة حيث اننا نعمل على رضاء العميل حيث نعطية مايرضية من اعمل التنظيف فنحن شركة تنظيف فلل بالدمام والخبر نتخصص فى نظافة الفلل بالدمام فتنظيف الفلة من الاعلى الى الاسفل حتى الحوش ونقوم ايضا كــ شركة تنظيف شقق بالدمام والخبر بنظافة الشقة من ارضيات وجدران وحمامات ومطابخ فهناك اشكال مختلفة من الشقق بالدمام ولكن الشقة التى نقوم بتنظيفها لابد وان تكون مختلفة فشركة طيور الجنة تعطيك ما يرضيك ولدينا كــ شركة تنظيف منازل بالدمام افضل طرق نظافة المنازل بالدمام والخبر وهناك شركة تنظيف موكيت بالدمام والخبر حيث اننا نقوم بغسيل الموكيت بافضل طرق التنظيف وافضل ماكينات التنظيف وهذا ما يميز شركتنا عن باقى شركات الرياض لاننا افضل شركة تنظيف بالخبر والخبر وعندنا تجد شركة تنظيف مجالس بالدمام والخبر حيث غسيل المجالس بطرقنا الخاصة ولدينا فرع شركة تنظيف كنب بالدمام ونقدم لكم فرع شركة جلى بلاط بالدمام للقيام بخدمات الجلى

    شركة مكافحة حشرات بالدمام تقدم افضل مكافحة للحشرات باستخدام افضل المبيدات الحشرية القوية والقادرة على مكافحة كافة انواع الحشرات والقضاء عليها نهائيا تعبر شركة طيور الجنه افضل شركة رش مبيدات بالدمام

    نقدم لكم خدماتنا المميزة بطبعها فقط في شركة تسليك مجارى بالدمام الخدمة الاكثر جودة و الاقل ثمنا الان و لاول مرة احصل على مجاري نظيفة و ليست بها اية روائح كريهة فنحن عبارة عن فريق دو خبرة سنوات في تسليك المجاري بالدمام باحدث الطرق و التقنيات التي لم يسبق لاحد تجربتها

  7. Oh my goodness! Incredible article dude! Thanks, However I
    am going through problems with your RSS. I don’t understand the reason why I cannot join it.
    Is there anyone else having the same RSS problems?

    Anyone who knows the answer will you kindly respond? Thanx!!

  8. Hi mates, its fantastic article about cultureand entirely explained, keep it up all the time.

  9. Its like you learn my thoughts! You appear to understand a
    lot approximately this, like you wrote the book
    in it or something. I think that you just can do with a few percent to drive the message house a bit, however
    instead of that, that is excellent blog. A great read.
    I will certainly be back.

  10. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and set up
    my own. Do you need any coding expertise to make your own blog?
    Any help would be greatly appreciated!