This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Description: | |
# Activate the site feature on all sub-sites | |
# This feature creates custom list | |
# | |
# Created Date: | |
# v1.0 - 27-11-2017 | |
# | |
# Author: | |
# Vikas Bansal | |
# | |
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | |
#feature ID to create custom list | |
$FeatureID="3e0d7f50-a6b7-45a6-b5a1-77950ef4327f" | |
#get all webs (sub-sites) under site collection | |
$WebsColl = Get-SPSite https://sp2013.com | Get-SPWeb -Limit ALL | |
#get the Feature | |
$Feature = Get-SPFeature -Limit All | Where { $_.ID -eq $FeatureID } | |
#check if Feature exists | |
if($Feature -ne $null) { | |
Write-Host "feature exists" -ForegroundColor DarkBlue -BackgroundColor Yellow | |
#iterate through through each sub-site activate the feature | |
foreach($web in $WebsColl){ | |
#check if the Feature is activated | |
if (Get-SPFeature -web $web.Url | Where {$_.ID -eq $FeatureId}) { | |
Write-Host "feature is already activated on " $web.Url -ForegroundColor DarkBlue -BackgroundColor Yellow | |
} | |
else { | |
Write-Host "feature not activated on " $web.Url -ForegroundColor Yellow -BackgroundColor Red | |
#Activate the Feature | |
Enable-SPFeature –identity $FeatureID -URL $web.URL -Confirm:$false | |
Write-Host "feature is activated now on " $web.Url -ForegroundColor DarkBlue -BackgroundColor White | |
} | |
} | |
} | |
else { | |
Write-Host "feature does not exists" -ForegroundColor Yellow -BackgroundColor Red | |
} |
No comments:
Post a Comment