Tuesday, April 5, 2016

Powershell script to generate powershell script to toggle publish feature

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$url = {your url here}
$site = get-spsite $url
$feature = $site.features.Item('f6924d36-2fa8-4f0b-b16d-06b7250180fa')
        
    if($feature -ne $null)
       {
            $ConfirmPreference = 'None'
       #     $feature
       #     Write-Host Disable-SPFeature -Identity $feature.DefinitionId -Url $site.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $site.Url  -Force   -WarningAction SilentlyContinue
      
       }
foreach($w in $site.AllWebs)
{
  #  Write-Host '#--------------------------------------------------------------------------------------'
  #  $w.Url
    $feature = $w.features.Item('94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb')
        
    if($feature -ne $null)
       {
       $ConfirmPreference = 'None'
         #   $feature
         #  Write-Host  Disable-SPFeature -Identity $feature.DefinitionId -Url $w.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $w.Url  -Force   -WarningAction SilentlyContinue
      
       }

}

No comments:

Post a Comment