0
Get-SPWebApplication "mysiteurl" | Get-SPSite -Limit All | Get-SPWeb -Limit ALL | % {Enable-SPFeature "Some_Feature_Id"} -Url $_.Url

I am trying to use the above Power Shell script to activate Site scoped feature in my news feed and all the My Sites in Share point 2013. But I am getting the below error:

ForEach-Object : Cannot bind parameter 'RemainingScripts'. Cannot convert the "-Url" value of type "System.String" to type "System.Management.Automation.ScriptBlock".

Can any one Please tell me what I should do.

  • It seems you are missing the ForEach code. Can you update the question with the complete code – Amal Hashim Nov 25 '14 at 15:07
  • looks like you have copy paste error, white space or special characters copied. Retype the above command in the powershell windows and try again. Otherwise your script have no issue. – Waqas Sarwar MVP Nov 25 '14 at 15:51
1

I would like to thank anyone that has viewed my question and kindly replied to me.

The above scripts didn't work for me. I was getting the following error:

Get-SPSite : A positional parameter cannot be found that accepts argument '$null'. At line:3 char:20 + $siteCollections = Get-SPSite –WebApplication "Some-Site + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-SPSite], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.SharePoint.PowerShell.SPCmdletGetSite

So the below script works just fine:

$feature = Get-SPFeature -Id some-feature-Id

$siteCollections = Get-SPSite –WebApplication Some-Site

foreach($siteCollection in $siteCollections)
{


   Write-Host "Activating" $feature.DisplayName "on" $siteCollection.Url

   Enable-SPFeature $feature -Url $siteCollection.Url 

}

To Disable features just replace Enable with Disable

| improve this answer | |
  • Hi @user2220658 , If you solved the problem stated in your original question, you should mark this answer as accepted answer to help future visitors. – Mohamed El-Qassas MVP Jun 7 '17 at 18:57
0

To enable feature on all sites of a particular web application. Use below script

Get-SPWebApplication"“<WebApplicationURL>" | Get-SPSite -Limit ALL |ForEach-Object {Enable-SPFeature “MyFeatureID” -Url $_.Url -confirm:$false}’

Source http://www.greggalipeau.com/2011/08/23/sharepoint-2010-powershell-enabledisable-feature-for-all-site-collections/

| improve this answer | |
0

Get the web application. Loop through all site collections inside it and compare the WebTemplate to SPSMSITE#0 (My Site Template) and then activate the given feature.

$SPWebApp = Get-SPWebApplication 'Web application Url'
$FeatureId = 'Feature ID'
foreach ($SPSite in $SPWebApp.Sites)
{
    if( $SPSite.RootWeb.WebTemplate -eq "SPSMSITE#0" )
    {
        enable-spfeature -Force -URL $SPSite.URL -identity $FeatureId -confirm:$false
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.