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

[玩转系统] 使用 PowerShell 激活 SharePoint 中所有网站上的功能

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

使用 PowerShell 激活 SharePoint 中所有网站上的功能


在某些情况下,您可能必须为 SharePoint 中的所有网站或网站集激活一项功能。就我而言,我必须激活 SharePoint 的“在客户端中打开”功能,才能对 SharePoint Web 应用程序中的所有网站集禁用基于浏览器的编辑。这篇博文将向您展示如何使用 PowerShell 一次性激活所有 SharePoint 网站上的功能。如果您想在整个农场中激活一项功能,这是一个非常方便的技巧。

如何激活 SharePoint 中的功能?

要从 SharePoint Web UI 激活网站集功能,您可以导航到网站设置 >> 网站集功能 >> 单击相关功能旁边的“激活”。

[玩转系统] 使用 PowerShell 激活 SharePoint 中所有网站上的功能

通过用户界面非常简单,不是吗?那么,如果您必须对 Web 应用程序中的数十个网站集执行相同的操作,PowerShell 是完美的解决方案。

激活 SharePoint 中所有网站集的功能


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$WebAppURL="https://portal.crescent.com/"
$FeatureName="OpenInClient" #Feature Folder Name

#Get all site collections of the web app and iterate through
$SiteColl= Get-SPSite -WebApplication $WebAppURL -Limit ALL
Foreach($Site in $SiteColl)
{ 
 #Get the Feature ID from Feature Name
    $Feature = Get-SPFeature -Site $Site.Url | Where {$_.DisplayName -eq $FeatureName}
 
 #If Feature Found
 if($Feature -ne $null)
    {
       #Check if the Feature is activated already
       if (Get-SPFeature -Site $Site.Url | Where {$_.ID -eq $Feature.Id})
       {
         Write-Host $FeatureName "is already activated at " $Site.Url -f Yellow
        }
       else
       {
       #Activate the Feature
       Enable-SPFeature -identity $Feature.ID -URL $Site.URL
       Write-Host "Feature Activated on "$site.URL -f Green   
  }
 }
 else
 {
      Write-Host "Feature Name doesn't exist:"$FeatureName -f Red
 } 
}

此 PowerShell 脚本会激活所有网站集上的该功能。

您还可以使用这一行来激活所有网站集上的一项功能:(但是,没有错误处理!)


Get-SPSite -Limit All | foreach {Enable-SPFeature "0561d315-d5db-4736-929e-26da142812c5" -url $_.URL } 

SharePoint:激活所有网站上的功能

考虑一个场景,您必须在网站集下的 100 个网站上激活网站级(Web)功能,这很常见。就我而言,我必须在特定网站集中的所有子网站上激活 Nintex Workflow 2013 功能。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteCollURL="https://portal.crescent.com/"
$FeatureID="0561d315-d5db-4736-929e-26da142812c5" 

#Get the Feature
$Feature = Get-SPFeature | Where {$_.ID -eq $FeatureID}

#If Feature Found
if($Feature -ne $null)
{     
    #Get all sites under the collection and loop through
    $Site= Get-SPSite $SiteCollURL
    Foreach($Web in $Site.AllWebs)
    {
  #Check if the Feature is activated already
       if (Get-SPFeature -Web $web.Url | Where {$_.ID -eq $FeatureId})
       {
         Write-Host $FeatureID "is already activated at " $Web.Url -f "Blue"
        }
       else
       {
           #Activate the Feature
           Enable-SPFeature -identity $FeatureID -URL $Web.URL
           Write-Host "Feature has been Activated on "$Web.URL -f "Green"
       }
    }
}
else    
{
    Write-Host "Feature doesn't exist:"$FeatureID -f "Red"
}

此脚本激活 SharePoint 中所有网站的功能。

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

取消回复欢迎 发表评论:

关灯