Jun 15 2018 12:57 PM
Hello Everyone,
I have come across a strange issue when using the PowerShell Script using CSOM for activating Publishing feature in SharePoint Online site collection. When i activated using the below script - I see that the Pages & Images library are not getting created. Can anyone help in finding out the issue here.
=====================
Input CSV passed with feature ids -
Site | f6924d36-2fa8-4f0b-b16d-06b7250180fa |
Web | 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb |
==================================
# Activate the Site Collection Feature
function EnableSiteCollectionFeature(){
try{
$site = $ctx.Site
#Check the Feature Status
$FeatureStatus = $site.Features.GetById($siteFeatureId)
$FeatureStatus.Retrieve("DefinitionId")
$ctx.Load($FeatureStatus)
$ctx.ExecuteQuery()
#Activate the feature if its not enabled already
if($FeatureStatus.DefinitionId -eq $null) {
# Add the feature using feature id and scope.
$newSiteFeature = $site.Features.Add($siteFeatureId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$newSiteFeature.Retrieve("DisplayName")
$ctx.Load($newSiteFeature)
$ctx.ExecuteQuery()
if($newSiteFeature.DefinitionId -ne $null){
Write-Host $newSiteFeature.DisplayName "Site Collection Feature activated"
}
}
}
catch{
Write-Host "Error in activating site Collection feature - $siteURL : $($_.Exception.Message)" -ForegroundColor Red
}
}
# Activate the Site Features
function EnableSiteFeature(){
try{
$site = $ctx.Web
#Check the Feature Status
$FeatureStatus = $site.Features.GetById($siteFeatureId)
$FeatureStatus.Retrieve("DefinitionId")
$ctx.Load($FeatureStatus)
$ctx.ExecuteQuery()
#Activate the feature if its not enabled already
if($FeatureStatus.DefinitionId -eq $null) {
# Add the feature using feature id and scope.
$newSiteFeature = $site.Features.Add($siteFeatureId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$newSiteFeature.Retrieve("DisplayName")
$ctx.Load($newSiteFeature)
$ctx.ExecuteQuery()
if($newSiteFeature.DefinitionId -ne $null){
Write-Host $newSiteFeature.DisplayName "Site Feature activated"
}
}
}
catch{
Write-Host "Error in activating site feature - $siteURL : $($_.Exception.Message)" -ForegroundColor Red
}
}
Thanks & Regards,
Bhanu