#********** Active Site publishing Collection Feature *********************************************
$siteCollectionFile = 'C:\doc\Get_SiteCollections_url.csv'
$host.Runspace.ThreadOptions = "ReuseThread"
function Enable-SPOFeature
{
param ($sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
try
{
#Adding the Client OM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#SPO Client Object Model Context
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
$spoCtx.Credentials = $spoCredentials
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Enabling the Feature with GUID $sFeatureGuid !!" -ForegroundColor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$guiFeatureGuid = [System.Guid] $sFeatureGuid
$spoSite=$spoCtx.Site
$spoSite.Features.Add($sFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$spoCtx.ExecuteQuery()
$spoCtx.Dispose()
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Required Parameters
$sUserName = "[email protected]"
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
#SharePoint Server Publishing Infrastructure
$sFeatureGuid = "f6924d36-2fa8-4f0b-b16d-06b7250180fa"
Import-Csv $siteCollectionFile |
where {
Write-Host $_.URL " Publishing feature activating"
$error.Clear()
try
{
Enable-SPOFeature -sSiteColUrl $_.URL -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid
if($error[0])
{
Write-Host $_.URL " feature activation failed"
$_.URL + " feature activation failed for feature: Publishing" >> ".\FeatureActivationLog.txt"
}
else
{
Write-Host $_.URL " feature activation successfull"
$_.URL + " feature activation successfull for feature: Publishing" >> ".\FeatureActivationLog.txt"
}
}
catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host $_.URL " feature activation failed"
$_.URL + " feature activation failed for feature: Publishing" >> ".\FeatureActivationLog.txt"
}
finally
{
}
}In this code we will learn about how to using PowerShell Script activate publishing feature
