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

[玩转系统] SharePoint Online:检查是否使用 PowerShell 激活了功能

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

SharePoint Online:检查是否使用 PowerShell 激活了功能


要求:PowerShell 检查 SharePoint Online 中的功能是否已激活。

如何检查 SharePoint 中是否启用了特定功能?

如果您是 SharePoint 管理员,您可能会发现自己需要知道您的环境中是否激活了特定功能。这篇博文将向您展示如何使用 PowerShell 检查您的 SharePoint Online 租户上是否激活了特定功能。这在排除问题或验证某些功能是否已启用时非常有用。

要检查 SharePoint 功能的当前状态,请说:发布功能 - 请执行以下步骤:

  1. 导航至“网站设置”>> 单击“网站集管理”下的“网站集功能”链接(如果是网站级功能,请使用:“网站操作”组下的“管理网站功能”链接!)
  2. 检查您的功能旁边的按钮。如果按钮仅显示“激活”,则该功能未激活。如果按钮显示“停用”并且“激活”按钮突出显示,则该功能已激活。

    [玩转系统] SharePoint Online:检查是否使用 PowerShell 激活了功能

SharePoint Online:用于检查功能是否已激活的 PowerShell

在启用或禁用 SharePoint Online 中的某个功能之前,我们可以使用此脚本在 PowerShell 中检查该功能的当前状态。让我们以“发布功能”为例,检查其在“Web”和“Site”范围中的状态。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$SiteFeatureGUID="f6924d36-2fa8-4f0b-b16d-06b7250180fa" #Publishing Feature - Site Scope
$WebFeatureGUID ="94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" #Publishing Feature - Web Scope

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Check the Site Collection Feature Status
    $SiteFeatureStatus =  $Ctx.Site.Features.GetById($SiteFeatureGuid)
    $SiteFeatureStatus.Retrieve("DefinitionId")
    $Ctx.Load($SiteFeatureStatus)
    $Ctx.ExecuteQuery()
 
    #Get the Site Collection Feature Status : Activated or not Activated
    if($SiteFeatureStatus.DefinitionId -ne $null)
    {
        Write-host -f Green "Site Collection Feature is Activated!"
    }
    else
    {
        Write-host -f Red "Site Collection Feature is Not Activated!"
    }

    #Get the Web Feature Status
    $WebFeatureStatus =  $Ctx.Web.Features.GetById($WebFeatureGuid)
    $WebFeatureStatus.Retrieve("DefinitionId")
    $Ctx.Load($WebFeatureStatus)
    $Ctx.ExecuteQuery()
 
    #Get the Site Collection Feature Status : Activated or not Activated
    if($WebFeatureStatus.DefinitionId -ne $null)
    {
        Write-host -f Green "Site Feature is Activated!"
    }
    else
    {
        Write-host -f Red "Site Feature is Not Activated!"
    }
}
Catch {
    write-host -f Red "Error Getting Feature Status!" $_.Exception.Message
}

因此,您需要做的就是:在脚本中设置功能 GUID(如何在 SharePoint 中获取功能 GUID?)和站点 URL 参数。

PnP PowerShell 检查 SharePoint Online 网站中的功能是否处于活动状态

使用此 PnP PowerShell cmdlet Get-PnPFeature 检查 SharePoint Online 网站上的功能是否已激活。


#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"
$FeatureId = "7c637b23-06c4-472d-9a9a-7c175762c5c4" #Limited Access user permission Lockdown mode feature

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#get the Feature
$Feature = Get-PnPFeature -Scope Site -Identity $featureId 

#Get the Feature status
If($Feature.DefinitionId -ne $null)
{
    Write-host -f Green "Site Collection Feature is Activated!"
}
Else
{
    Write-host -f Red "Site Collection Feature is Not Activated!"
}

您可以将范围更改为“Web”来检查 Web 范围的功能是否处于活动状态!

总之,我们讨论了如何使用网站设置和 PowerShell 检查 SharePoint Online 中的功能是否已激活。按照本指南中概述的步骤,您可以在 SharePoint Online 环境中执行操作之前快速轻松地验证特定功能是否已激活。以下是我使用 PowerShell 激活或禁用 SharePoint Online 功能的相关帖子:

  • 如何使用 PowerShell 启用 SharePoint Online 中的功能?
  • SharePoint Online:使用 PowerShell 停用功能

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

取消回复欢迎 发表评论:

关灯