当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何在 SharePoint 中使用 PowerShell 激活发布功能?

作者:精品下载站 日期:2024-12-14 14:13:45 浏览:14 分类:玩电脑

如何在 SharePoint 中使用 PowerShell 激活发布功能?


要求: SharePoint 发布网站用于创建公共网站、内联网门户等。我们必须在以下场景中使用 PowerShell 激活 SharePoint 中的发布功能:

  • 通过网页界面激活发布功能导致错误!
  • 批量激活 Web 应用程序中所有网站集和网站的发布功能。

可以手动或通过 PowerShell 脚本激活发布功能。在这篇文章中,我们将向您展示如何使用 PowerShell 激活该功能。

使用 PowerShell 激活 SharePoint 中的发布功能:

发布网站依赖于“SharePoint Server 发布基础结构”功能,该功能需要在网站集和网站级别激活。要激活发布功能,请执行以下操作:

  • 导航至“网站设置”>> 单击“网站集管理”下的“网站集功能”链接
  • 单击“SharePoint Server Publishing Infrastructure”旁边的“激活”按钮

    [玩转系统] 如何在 SharePoint 中使用 PowerShell 激活发布功能?

SharePoint PowerShell 在网站集中激活发布功能:

以下是用于激活网站集发布功能的 PowerShell。


Enable-SPFeature -Identity "PublishingSite" -url "https://intranet.crescent.com"

让我们向其中添加一些错误处理和变量:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$SiteURL="https://intranet.crescent.com"
$FeatureName = "PublishingSite"

#Check if publishing feature is already activated in the site collection
$Feature = Get-SPFeature -site $siteURL | Where-object {$_.DisplayName -eq $FeatureName}
if($Feature -eq $null)
{    
    #Enable the Publishing feature 
    Enable-SPFeature -Identity $FeatureName -url $SiteURL -Confirm:$False
   
    Write-host "Publishing Feature Activated on $($SiteURL)" -ForegroundColor Green    
}
else
{
    Write-host "Publishing Feature is already Active on $($SiteURL)" -ForegroundColor Red
}

在网站级别启用 SharePoint 服务器发布:

我们还必须在站点级别激活发布功能。

  • 返回网站设置页面 >> 单击“网站操作”组下的“管理网站功能”链接
  • 单击“SharePoint Server Publishing”旁边的激活按钮

这启用了 Web 级别的发布功能。要使用 PowerShell 激活 SharePoint 服务器发布,请使用以下脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebURL="https://intranet.crescent.com/Sales/"
$FeatureName = "PublishingWeb"

#Check if publishing feature is already activated in the site 
$Feature = Get-SPFeature -Web $WebURL | Where-object {$_.DisplayName -eq $FeatureName}
if($Feature -eq $null)
{    
    #Enable the Publishing feature 
    Enable-SPFeature -Identity $FeatureName -url $WebURL -Confirm:$False
   
    Write-host "Publishing Feature Activated on $($WebURL)" -ForegroundColor Green    
}
else
{
    Write-host "Publishing Feature is already Active on $($WebURL)" -ForegroundColor Red
}
必须在网站集中启用发布功能,然后才能将其启用到子网站!

使用 PowerShell 为 Web 应用程序中的所有网站集和网站激活 SharePoint 服务器发布基础结构:

有时,您可能必须使用 PowerShell 为整个网站集中的所有网站甚至整个 Web 应用程序中的所有网站集激活或停用 SharePoint 服务器发布基础结构。这是脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebAppURL="https://intranet.crescent.com"
$SiteFeatureName = "PublishingSite"
$WebFeatureName = "PublishingWeb"

#Get all site collections of the web app and iterate through
$SiteColl= Get-SPSite -WebApplication $WebAppURL -Limit ALL
Foreach($Site in $SiteColl)
{ 
    write-host "Processing site collection:"$Site.URL -ForegroundColor Yellow 
    #Check if publishing feature is already activated in the site 
    $Feature = Get-SPFeature -Site $Site.URL | Where-object {$_.DisplayName -eq $SiteFeatureName}

    if($Feature -eq $null)
    {    
        #Enable the Publishing feature 
        Enable-SPFeature -Identity $SiteFeatureName -url $Site.URL -Confirm:$False
   
        Write-host "Publishing Feature Activated on $($Site.URL)" -ForegroundColor Green    
    }
    else
    {
        Write-host "Publishing Feature is already Active on $($Site.URL)" -ForegroundColor Red
    }

    #Loop through each web in the site collection
    Foreach($Web in $Site.AllWebs)
    {
        write-host "Processing Web"$Web.URL -ForegroundColor Yellow
        #Check if publishing feature is already activated in the web 
        $Feature = Get-SPFeature -Web $Web.URL | Where-object {$_.DisplayName -eq $WebFeatureName}
        if($Feature -eq $null)
        {    
            #Enable the Publishing feature 
            Enable-SPFeature -Identity $WebFeatureName -url $Web.URL -Confirm:$False
   
            Write-host "Publishing Feature Activated on $($Web.URL)" -ForegroundColor Green    
        }
        else
        {
            Write-host "Publishing Feature is already Active on $($Web.URL)" -ForegroundColor Red
        }
    }
}

要在 SharePoint Online 中使用 PowerShell 激活功能,请使用:如何使用 PowerShell 在 SharePoint Online 中激活发布功能?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯