Thursday, March 30, 2017

PowerShell - Enumerates through all site collections for a given web application, then enumerates through all subsites within each site collection and deactivate the given web level feature

 

Add-PsSnapin Microsoft.SharePoint.PowerShell

## SharePoint DLL

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$webApplicationURL = "webApplicationURL"

$webApp = Get-SPWebApplication $webApplicationURL

$featurefolder = "FollowingContent"

if($webApp -ne $null)

{

foreach($site in $webApp.Sites)

{

if($site -ne $null)

{

foreach($subWeb in $site.AllWebs)

{

      if($subWeb -ne $null)

      {

           Try

           {

           Disable-SPFeature -identity $featurefolder -Confirm:$false –URL  $subWeb.url -ErrorAction Stop

            Write-Output $subWeb " : Following Content Feature is Deactivated"

           }

          Catch

          {

          Write-Output $subWeb " : already Deactivated"

          }

    $subWeb.Dispose()

}

}        

$site.Dispose()

}}}

Remove-PsSnapin Microsoft.SharePoint.PowerShell

No comments:

Post a Comment