TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Using PowerShell Script Activate Publishing Feature
Sushant Kesari
Oct 16
2015
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#********** 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
{
}
}
SharePoint
activate publishing feature