[玩转系统] SharePoint Online:使用 PowerShell 激活功能
作者:精品下载站 日期:2024-12-15 00:01:24 浏览:16 分类:玩电脑
SharePoint Online:使用 PowerShell 激活功能
要求:使用 PowerShell 激活 SharePoint Online 网站集中的功能。
解决方案:在 SharePoint 本地部署中,我们使用 Enable-SPFeature cmdlet 来激活/启用功能。在 SharePoint Online 中,没有这样的 cmdlet 可通过 PowerShell 来激活该功能。但我们可以利用客户端对象模型 (CSOM) 来激活 SharePoint Online 中的功能。让我们激活“SharePoint Server 发布基础架构”功能。以下是用于激活网站集功能的 SharePoint Online PowerShell 示例:
确保您的客户端计算机上安装了 SharePoint Online 客户端 SDK 才能使用此代码。您可以从以下位置下载:https://www.microsoft.com/en-us/download/details.aspx?id=42038如何启用 SharePoint Online 中的功能?
激活功能使与该功能相关的功能可用。它可以带来新的功能或项目,例如列表和库等。以下是如何在 SharePoint Online 中激活网站功能:
- 导航到需要激活该功能的站点。
- 在网站的主页上,单击“设置”齿轮图标,然后单击“设置”菜单中的“网站设置”选项。
- 在“站点设置”页面上,单击“站点操作”部分下的“管理站点功能”链接。
例如,以下是如何激活 SharePoint Online 中的发布功能:在“网站功能”页面上,单击要激活的网站功能旁边的“激活”按钮。
- 功能状态更改为“活动”,并在站点上启用关联的功能。
PowerShell 在 SharePoint Online 中启用网站集功能
您需要快速启用 SharePoint Online 中的某项功能吗? PowerShell 可以帮助启用 SharePoint Online 中的功能,而无需使用 Web 浏览器 GUI!让我向您展示如何使用 PowerShell 启用 SharePoint Online 中的功能:
#Load SharePoint CSOM Assemblies
Import-Module Microsoft.Online.SharePoint.Powershell
#Variables for Processing
$SiteURL = "https://crescent.sharepoint.com/Sites/Sales"
$FeatureGUID =[System.GUID]("f6924d36-2fa8-4f0b-b16d-06b7250180fa") #Publishing Feature ID
$LoginName ="[email protected]"
$LoginPassword ="Password"
#Get the Client Context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
#Login Credentials
$SecurePWD = ConvertTo-SecureString $LoginPassword -asplaintext -force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $LoginName, $SecurePWD
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.UserName,$Credential.Password)
#Get the Site
$site = $ctx.site
#sharepoint online powershell activate feature
$site.Features.Add($FeatureGUID, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::farm)
$ctx.ExecuteQuery()
write-host "Feature has been Activated!"
此 PowerShell 支持 SharePoint Online 中的发布功能。
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 Enable Feature in SharePoint Online
Function Enable-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()
#sharepoint online activate feature using powershell (if its not enabled already)
if($FeatureStatus.DefinitionId -eq $null)
{
Write-Host "Enabling Feature $FeatureGuid..." -ForegroundColor Yellow
$Site.Features.Add($FeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null
$Ctx.ExecuteQuery()
Write-Host "Feature Enabled on site $SiteCollURL!" -ForegroundColor Green
}
else
{
Write-host "Feature is Already 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
#sharepoint online enable feature powershell
Enable-SPOFeature -SiteCollURL $SiteCollURL -UserName $UserName -Password $SecurePassword -FeatureGuid $FeatureGuid
这将激活 SharePoint Online 中的 SharePoint Server 发布基础结构功能。
要激活所有 SharePoint Online 网站上的功能,请使用:如何使用 PowerShell 在 SharePoint Online 中的所有网站上启用功能?如何使用PowerShell激活网站功能(Web)?
虽然上述代码激活网站集级别功能,但相同的代码也可用于激活任何 Web 级别功能。更改线路:
$Site=$Ctx.site
到
$Site=$Ctx.web
另外,为 Web 级功能设置 GUID!这将使用 SharePoint Online 中的 PowerShell 激活该功能。
PnP PowerShell 在 SharePoint Online 中启用发布功能:
让我们使用 Enable-PnPFeature cmdlet 在网站集级别使用 PnP PowerShell 激活 SharePoint Online 功能。
#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 -eq $null)
{
#sharepoint online powershell enable feature
Write-host -f Yellow "Activating Feature..."
Enable-PnPFeature -Scope Site -Identity $FeatureId -Force
Write-host -f Green "Feature Activated Successfully!"
}
Else
{
Write-host -f Yellow "Feature is already active!"
}
同样,您可以在 Web 范围内使用 PnP PowerShell 激活发布功能,如下所示:
#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 to activate
$Feature = Get-PnPFeature -Scope Web -Identity $FeatureId
#Get the Feature status
If($Feature.DefinitionId -eq $null)
{
#activate publishing feature sharepoint online using powershell
Write-host -f Yellow "Activating Feature..."
Enable-PnPFeature -Scope Web -Identity $FeatureId -Force
Write-host -f Green "Feature Activated Successfully!"
}
Else
{
Write-host -f Yellow "Feature is already active!"
}
要使用 PowerShell 禁用 SharePoint Online 中的功能,请参阅:SharePoint Online:使用 PowerShell 停用功能
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[短剧合集] 2025年06月2日 精选+付费短剧推荐39部
[软件合集] 25年6月2日 精选软件18个
[软件合集] 25年6月1日 精选软件15个
[短剧合集] 2025年06月1日 精选+付费短剧推荐59部
[短剧] 2025年05月31日 精选+付费短剧推荐58部
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[美图] 2W美女个美女小姐姐,饱眼福
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag