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

[玩转系统] SharePoint Online:使用 PowerShell 停用功能

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

SharePoint Online:使用 PowerShell 停用功能


要求:使用 PowerShell 停用 SharePoint Online 中的功能。

如何停用 SharePoint Online 中的功能?

在 SharePoint Online 中,有时您可能需要停用某项功能。例如,如果您不再使用某个功能,或者它导致您的网站出现问题。在这篇博文中,我们将引导您禁用 SharePoint Online 功能。我们还将共享 PowerShell 脚本来禁用 SharePoint Online 中的功能。让我们开始吧!

请按照以下步骤停用 SharePoint Online 功能:

  1. 导航到需要停用该功能的站点。
  2. 在网站的主页上,单击“设置”齿轮图标,然后单击“设置”菜单中的“网站设置”选项。
  3. 单击“站点设置”页面上“站点操作”部分下的“管理站点功能”链接。
  4. 在“站点功能”页面中,单击要停用的站点功能旁边的“停用”按钮。
  5. 功能状态更改为,并且站点上关联的功能已禁用。

    [玩转系统] SharePoint Online:使用 PowerShell 停用功能

同样,使用“网站集管理”部分下的“网站集功能”链接来停用网站集功能。

SharePoint Online PowerShell 禁用功能:

以下是如何使用客户端对象模型和 PowerShell 禁用 SharePoint Online 功能。


#Load SharePoint Online 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"

#Function to Disable Feature in SharePoint Online
Function Disable-SPOFeature 
{ 
    param ($SiteCollURL,$UserName,$Password,$FeatureGuid)
    Try 
    {     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollURL)
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
        $Ctx.Credentials = $Credentials
        $Site=$Ctx.Site

        #Check the Feature Status
        $FeatureStatus =  $Site.Features.GetById($FeatureGuid)
        $FeatureStatus.Retrieve("DefinitionId")
        $Ctx.Load($FeatureStatus)
        $Ctx.ExecuteQuery()

        #Deactivate the feature if its enabled
        if($FeatureStatus.DefinitionId -ne $null)
        {
            Write-Host "Disabling Feature $FeatureGuid..." -ForegroundColor Yellow
            $Site.Features.Remove($FeatureGuid, $true) | Out-Null
            $Ctx.ExecuteQuery()
            Write-Host "Feature has been disabled on site $SiteCollURL!" -ForegroundColor Green
        }
        else
        {
            Write-host "Feature is Not Active on the Site collection!" -ForegroundColor Red
        }
    } 
    Catch
    {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
 
#Parameters to Activate Feature
$SiteCollURL = "https://Crescent.sharepoint.com/sites/Demo"
$UserName = "[email protected]"
$Password = "Password goes here"
$FeatureGuid= [System.Guid] ("f6924d36-2fa8-4f0b-b16d-06b7250180fa") #Publishing Feature
$SecurePassword= ConvertTo-SecureString $Password -asplaintext -force  

#Disable Feature
Disable-SPOFeature -SiteCollURL $SiteCollURL -UserName $UserName -Password $SecurePassword -FeatureGuid $FeatureGuid

这将停用 SharePoint Online 中使用 PowerShell 的发布功能。如果您不再需要该功能,这可能会很有帮助。

SharePoint Online:使用 PnP PowerShell 停用功能

您可以使用 PowerShell 禁用 SharePoint Online 中的功能。让我们使用 PnP PowerShell cmdlet Disable-PnPFeature 在站点级别禁用发布功能。为此,您需要使用 Connect-PnPOnline 连接到 SharePoint Online 网站。连接后,您需要运行包含参数、要禁用的功能的 ID 以及功能范围的 Disable-PnPFeature cmdlet。例如,如果您要禁用“https://crescent.sharepoint.com”网站上的“发布功能”功能,您可以运行以下 cmdlet:Disable-PnPFeature -Identity “f6924d36-2fa8-4f0b-b16d- 06b7250180fa”-范围“站点”。


#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Procurement"
$FeatureId = "f6924d36-2fa8-4f0b-b16d-06b7250180fa" #Site Scoped Publishing 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)
{    
    #Deactivate the Feature
    Write-host -f Yellow "Deactivating Feature..."
    Disable-PnPFeature -Scope Site -Identity $FeatureId -Force

    Write-host -f Green "Feature Deactivated Successfully!"
}
Else
{
    Write-host -f Yellow "Feature is Not active!"
} 

同样,要使用 PnP PowerShell 在 Web 级别禁用 SharePoint Online 中的功能,请使用:


#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Procurement"
$FeatureId = "94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" #Web Scoped Publishing Feature

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

#get the Feature
$Feature = Get-PnPFeature -Scope Web -Identity $FeatureId 

#Get the Feature status
If($Feature.DefinitionId -ne $null)
{    
    #Activate the Feature
    Write-host -f Yellow "Deactivating Feature..."
    Disable-PnPFeature -Scope Web -Identity $FeatureId -Force

    Write-host -f Green "Feature Deactivated Successfully!"
}
Else
{
    Write-host -f Yellow "Feature is Not active!"
}

如何在 PowerShell 中激活网站集功能?要使用 PowerShell 激活 SharePoint Online 中的功能,请参阅:如何使用 PowerShell 激活 SharePoint Online 中的功能?

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

取消回复欢迎 发表评论:

关灯