I am trying to activate a Site scoped feature using a powershell script. I have another scrip which deploys my solution and I see my feature is installed correctly in Site Collection feature gallery. On executing the below function I get "feature not found" as my custom message. I am confused between what URL I should pass in the my function.
Here are the URLs
WebApplication : http://myWebapplication
Site Collection: http://myWebapplication/sites/mySiteCollection
Web Site: http://myWebapplication/sites/mySiteCollection/myWebSite
function ActivateWebFeatures()
{
if ($webLevelFeatures -ne $null) --Arrary that stores feature names
{
$spSiteCollection = Get-SPSite "http://myWebapplication/sites/mySiteCollection"
if($spSiteCollection -ne $null)
{
#Cycle through all webs in the collection and activate all the features
foreach($spWeb in $spSiteCollection.AllWebs)
{
foreach($webFeatureName in $webLevelFeatures)
{
$webFeature = Get-SPFeature -Web $spSiteCollection | where-object {$_.displayname -eq $webFeatureName} -ErrorAction:Inquire
if ($webFeature -ne $null)
{
InformationMessage "Trying to activate $webFeatureName at $spWeb.url"
Enable-SPFeature –identity $webFeatureName -URL $spSiteCollection -Confirm:$false -ErrorAction:SilentlyContinue
}
else
{
InformationMessage "$webFeatureName feature not found"
}
}
}
}