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

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

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

使用 PowerShell 在 SharePoint 中的所有网站集上激活/停用功能


我们在 SharePoint 2013 中使用“Enable-SPFeature”和“Disable-SPFeature”PowerShell cmdlet/SharePoint 2016 网站激活或停用功能,如我的另一篇文章:如何激活-停用 SharePoint 中的功能。有时,我们可能必须激活所有网站集的功能或停用所有网站上的功能。这是我的 PowerShell 脚本来执行此操作。

为 SharePoint 中的所有网站集启用一项功能:

就我而言,由于许可限制,我必须在 Web 应用程序下的每个网站集中启用“在客户端应用程序中打开文档”功能,以强制在 Office 客户端(例如 Microsoft Word)而不是 Office Web 应用程序中打开文档。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#variables
#$WebAppURL = "https://intranet.crescent.com"
$FeatureName ="OpenInClient"

#Get the Web Application
$webApp = Get-SPWebApplication -Identity $WebAppURL

#Get all site collections with in the web app
$SitesCollection = $WebApp | Get-SPSite -limit all 

#Iterate through each site 
foreach ($site in $SitesCollection)
{
    #Check if feature is already activated
    $feature = Get-SPFeature -site $site.Url  | Where-object {$_.DisplayName -eq $FeatureName}
    if($feature -eq $null)
    {    
        #Enable the feature 
        Enable-SPFeature -Identity $FeatureName -url $site.url -Confirm:$False
  
        Write-host "Feature Activated on $($site.URL)" -ForegroundColor Green    
    }
    else
    {
        Write-host "Feature is already Active on $($site.URL)" -ForegroundColor Red
    }
}

PowerShell 停用所有站点上的功能:

要求:在 SharePoint 2013 Web 应用程序的所有网站上停用“移动重定向”功能。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Variables
$WebAppURL = "https://intranet.crescent.com" 
$FeatureName = "MobilityRedirect"
 
#Disable Mobile View feature on all sites in the web application
$WebsCollection = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL
 
#Itereate through each web
ForEach($Web in $WebsCollection)
{
    #Check if feature is already activated
    $feature = Get-SPFeature -web $Web.Url  | Where-object {$_.DisplayName -eq $FeatureName}
 
    if($feature -ne $null)
    {
        #Disable the Mobile browser view feature
        Disable-SPFeature -identity $FeatureName -URL $Web.URL -Force -Confirm:$false
        write-host "Mobile Redirect feature deactivated at site: $($Web.Url)"
    }
}

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

取消回复欢迎 发表评论:

关灯