Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Using PowerShell Script Activate Publishing Feature
WhatsApp
Sushant Kesari
Oct 16
2015
1.5
k
0
0
#********** 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
Up Next
Using PowerShell Script Activate Publishing Feature