Question

What is the correct way of disabling a feature using PowerShell? I'm gonna add a script to task scheduler that's deactivates the Minimal Download Strategy feature from all the new sites that are created each day.

However, i can't come to a conclusion of which way is the correct way to do it.

$web = "http://server/sites/something"
$web.EnableMinimalDownload = $false
$web.Update()

Or

Disable-SPFeature -identity "Minimal Download Strategy" -URL "http://server/sites/something"

Are there any differences or are one way better then the other?

Was it helpful?

Solution

The first way is kind of manual way where you are creating the SPWeb object and then disabling the property of the object.

The second way is the correct method. It uses the Out of the box PowerShell CMDLet to disable the feature.

If you are planning to disable for all then use

foreach($webApp in Get-SPWebApplication)
{
    foreach ($SPsite in $webApp.Sites)
    {
       foreach($SPweb in $SPsite.AllWebs)
        {
             Disable-SPFeature –identity "MDSFeature" -URL $spweb.URL -confirm:$false
        }
    }
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top