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
$site.Dispose()

  • 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
$web.Dispose()

  • 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}
$site.Dispose()

44 comments:

  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)

    ReplyDelete
    Replies
    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.

      Delete
  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.

    ReplyDelete
  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

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

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

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

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

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

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

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

    ReplyDelete
  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.

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

    ReplyDelete

  11. I don't apperceive what it is about the bendable blow and matte finish, but I accept a anemic atom for printed suede Christisn Louboutin Outlet. One of the best brands to cull this off is YSL Wallet Outlet. I accept to acquaint you about a backpack attraction of mine. I am in fact mad at myself that I did not splurge on the Ralph Lauren Polo Outlet Croc Muse Two which has two colors that I admire with a sueced croc pattern. To see a formed suede accomplishment off a Red Bottoms Outlet that I already adore, my affection melts. Replica Watches are additionally pretty reflective of their user's persona. Amazing furthermore multi-colored Replica Watches are commonly worn because of the younger. Conversely, exquisite dress Swiss Rolex Replica are regularly sported by highly developed gentlemen. And then usually there's the luxurious Swiss Replica Watches worn by the individuals who're properly to complete. Check out observing your mates furthermore you can before long see how the layouts are actually ranging.

    ReplyDelete
  12. También puede visitar una tienda de ladrillo y mortero de Michael Kors o su sitio web y comprar directamente un bolso Michael Kors desde allí. Usar un bolso de Michael Kors les permite a los demás reconocer que el habitante urbano educado toma la moda realmente con seriedad. Los bolsos de hombro son particularmente refinados y elegantes.

    {Bolsas Michael Kors Precios | Bolsos Michael Kors Outlet | Michael Kors Rebajas}

    En vacker konstnärlig skapelse av vävt läder, som ger ett skalskaligt utseende - liknar en snakeskin eller fiskhud, linjer utsidan av påsen. Läderens bältros är små läderringar. Det finns också gyllene accenter på väskan. Slutresultatet är svagt liknar kedjepost.

    {Michael Kors Rea | Michael Kors Väska Rea | Michael Kors Plånbok}

    ReplyDelete
  13. Thank you for sharing an interesting and very useful article. And let me share an article about health here I believe this is useful. Thank you :)

    Cara Mengobati Penyakit Tipes Super Ampuh
    Cara Mengatasi Jantung Koroner secara Alami
    Obat Tradisional Penurun Asam Urat

    ReplyDelete
  14. This article is interesting and useful. Thank you for sharing. And let me share an article about health that God willing will be very useful. Thank you :)

    Obat Alami Menurunkan tekanan Darah Tinggi
    Obat Benjolan Di Ketiak
    Cara Mengobati Kencing Tersendat

    ReplyDelete
  15. A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
    There are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
    Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
    Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
    Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
    Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
    Coach Store Near Me trends come and go, but a Coach stands the test of time.
    The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
    Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
    All Michael Kors Outlet Online Store have serial numbers.

    ReplyDelete
  16. No matter what type of Michael Kors Bags Outlet each individual got, they all had one thing in common. We all know that getting something on sale is like winning a mini lottery, but to find a name brand handbag like Michael Kors Black Friday Sale for instance, discounted is like a slice of heaven on earth. I have personally attacked my husband with hugs and kisses when finding Official Coach Outlet Online at discounted prices.

    Michael Kors Factory Outlet stores can be found in malls all over. MK Outlet and other Coach merchandise can also be found in some boutiques. Inspired by the same material baseball gloves are made from, these Coach Bags On Sale Online are versatile and stylish. Since it's conception, the Michael Kors Handbags Outlet has been produced into a variety of designs, colors, shapes, and styles that have won top pick of millions of women the world over.

    New Michael Kors Bags are the most sought after handbag. Since Coach Outlet Online is one of the most recognized name brands in the world of fashion, you will find A-list celebrities down to small girls wearing them.

    tags:Coach Outlet|Coach Bags Factory Outlet|Coach Purses Outlet

    ReplyDelete