Enable Features Programatically in SP 2010

We're currently migrating from SP 2007 to SP 2010. We were using the SmartPart web part in 2007, and have downloaded the updated SmartPart dll. I need to loop through each site collection in the farm and activate the feature (we have hundreds of site collections).

I keep getting "Feature with Id [feature GUID] is not installed in this farm, and cannot be added to this scope."

The feature is, in fact, installed, and I can activate it manually through Site Settings.  Here is my code:

// Already inside the site collection
SPFeatureDefinition featureDefinition = SPFarm.Local.FeatureDefinitions["SmartParts_Feature1"];

Open in new window

Any insight would be greatly appreciated.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sushanta SahuPrincipal Specialist, Information ManagementCommented:
Powershell is the answer. Quick and easy!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RainverseAuthor Commented:
Powershell was indeed the answer, but a little more of an answer would have been helpful.
RainverseAuthor Commented:
Here's what I came up with:

$siteUrl = "http:\\ourExtranet.ourserver.com"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
foreach($site in $spWebApp.Sites)
    if ($site.Url.Contains("extranet/")){
        echo $site.Url
        Enable-SPFeature -Identity "SmartParts_Feature1" -URL $site.Url
        echo "Feature has been activated..."

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.