I would like a script that could activate multiple features (list of features) at once in a single site collection. I was wondering if anyone out there has done this already. Any help would be appreciated.
It is probably worth pointing out that the list of features in the text file should be ordered accordingly to take into account activation dependencies if any of the features are dependent on others in the list, otherwise the script would have to be run multiple times until all the features have been activated. I suppose you could inspect all the features listed in the text file first to determine if any of them are dependent on each other and activate them in the correct order. I don’t know if the Force parameter of Enable-SPFeature ignores feature dependencies, but it will rerun code in the feature receiver, which may cause problems depending on the code.
Got it. Change that part of the code with Vlad’s code but rest of the code should work.
Thanks Amit, I will give this a try. Although, I will not be using a SP List, but rather a .txt document on the local machine. I will use the Get-Content <some path> command.
Give following script a try. I am assuming (as you mentioned), you are maintaining a SharePoint list with all the feature GUIDS and these are all site collection features.
I have not verified the code but should work.
===================================================
$listTitle = “YOUR FETATURE GUID LIST TITLE”
$siteURL = Read-Host ‘Please enter site collection URL’
$site = Get-SPSite $siteURL
$web = $site.OpenWeb()
$list = $web.Lists[$listTitle]
foreach ($lstItem in $list.Items)
{
$featureGUID = $lstItem[“FEATURE GUID COLUMN NAME”]
$feature = $site.Features[$featureGUID]
if($feature -eq $null)
{
Enable-SPFeature -Identity $featureGUID –url $site.URL
}
}
PS script that runs and activates multiple features. The script would loop through a list, check if enabled; do nothing, if not enabled; enable. The list would contain feature Id’s. I will use only one param; that would be Site Collection URL (The features I need activated are scoped at the SPSite level).