[玩转系统] SharePoint Online:如何使用 PowerShell 创建网站集?
作者:精品下载站 日期:2024-12-14 14:15:42 浏览:14 分类:玩电脑
SharePoint Online:如何使用 PowerShell 创建网站集?
要求:使用 PowerShell 在 SharePoint Online 中创建新网站集。
如何在 SharePoint Online 中创建网站集?
在本指导演练中,我将向您展示如何使用 PowerShell 创建新的 SharePoint Online 网站集。毫无疑问,PowerShell 是在 SharePoint Online 中创建网站集更快、更有效的方法。让我们开始吧!
SharePoint 中的网站集是网站的逻辑组,具有公共顶级网站和按层次结构组织的子网站。每个网站集共享一个共同的顶级网站、导航、安全性、内容类型等。若要创建现代 SharePoint Online 网站集,请按照下列步骤操作:
- 以租户管理员或 SharePoint Online 管理员权限身份登录 SharePoint 管理中心。
- 单击左侧导航中的站点 >> 活动站点 >> 单击“创建”。
选择“团队网站”选项来创建包含 Office 365 组的现代团队网站集,或选择“其他选项”来创建不包含 Office 365 组的现代团队网站。
-
从 SharePoint 网站模板中,选择网站模板(例如“团队网站”),提供网站名称、网站地址和管理员选项,然后选择语言。单击“高级设置”以设置时区和站点描述。输入所有详细信息并在 SharePoint Online 中创建网站集后,单击“完成”。
稍等片刻,您的新式 SharePoint 网站集应出现在网站集列表中。
如何从 SharePoint 起始页创建 SharePoint Online 网站?
您还可以使用 SharePoint 主页 (https://tenant.sharepoint.com/_layouts/15/sharepoint.aspx) 创建 SharePoint 网站,只需转到 Office 365 应用程序启动器 >> 单击 SharePoint >> 单击工具栏中的“创建站点”按钮。 (除非 SharePoint 管理员或全局管理员禁用网站创建 - 默认情况下,它是启用的!因此,任何人都可以创建新网站)。
输入站点名称、描述、隐私设置和语言,设置组电子邮件地址,然后单击“下一步>>添加任何组成员以授予站点权限”,然后单击“完成”。这将创建 Microsoft 365 组连接的 SharePoint 网站集。
从 SharePoint 管理中心或 SharePoint 主页网站创建网站集是一项相对简单的任务,不是吗?现在,让我们看看如何使用 PowerShell 在 SharePoint Online 中创建网站集。
SharePoint Online:使用 PowerShell 创建现代团队网站集
团队网站是 SharePoint 中最常见的网站模板类型。顾名思义,团队网站是为各个团队、部门、职能组等的团队协作而创建的。您可以通过将网站模板指定为“STS#3”,在 SharePoint Online 中创建现代网站集。以下是如何使用 PowerShell 创建新的 SharePoint Online 网站:
#Connect to SharePoint Online
Connect-SPOService -url "https://crescent-admin.sharepoint.com" -Credential (Get-credential)
#Create a modern team site
New-SPOSite -Url "https://crescent.sharepoint.com/sites/Purchase" -Owner "[email protected]" -StorageQuota 2048 -Title "Purchase Team Site" -Template "STS#3"
Office 365 租户上创建的网站集的最大数量为 200 万个!
现在,让我们添加一些错误处理并将其包装在可重用函数中,以在 SharePoint Online 中使用 PowerShell 创建网站。
使用 PowerShell 创建 SharePoint Online 网站集:
让我们添加一些错误处理并使脚本更加灵活,以便 SharePoint Online 使用 PowerShell 创建网站集。
#powershell to create site collection sharepoint online
Function Create-SPOSite
{
param
(
[string]$Title = $(throw "Please Provide the Site Title!"),
[string]$URL = $(throw "Please Provide the Site URL!"),
[string]$Owner = $(throw "Please Provide the Site Owner!"),
[int]$StorageQuota = $(throw "Please Provide the Site Storage Quota!"),
[int]$ResourceQuota = $(throw "Please Provide the Site Resource Quota!"),
[string]$Template = $(throw "Please Provide the Site Template!")
)
#Connection parameters
$AdminURL = "https://Crescent-admin.sharepoint.com"
$AdminName = "[email protected]"
$AdminPassword="Password Goes here"
$SecurePassword = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePassword
Try{
#Connect to Office 365
Connect-SPOService -Url $AdminURL -Credential $Credentials
#Check if the site collection exists already
$SiteExists = Get-SPOSite | where {$_.url -eq $URL}
#Check if site exists in the recycle bin
$SiteExistsInRecycleBin = Get-SPODeletedSite | where {$_.url -eq $URL}
If($SiteExists -ne $null)
{
write-host "Site $($url) exists already!" -foregroundcolor red
}
elseIf($SiteExistsInRecycleBin -ne $null)
{
write-host "Site $($url) exists in the recycle bin!" -foregroundcolor red
}
else
{
#sharepoint online create site collection powershell
New-SPOSite -Url $URL -title $Title -Owner $Owner -StorageQuota $StorageQuota -NoWait -ResourceQuota $ResourceQuota -Template $Template
write-host "Site Collection $($url) Created Successfully!" -foregroundcolor Green
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Parameters to create new site collection
$SiteTitle = "Demo"
$SiteURL= "https://Crescent.sharepoint.com/sites/demos"
$SiteOwner = "[email protected]"
$StorageQuota = 1000
$ResourceQuota = 300
$SiteTemplate = "STS#3"
#Call The function to create new sharepoint online site using powershell
Create-SPOSite -Title $SiteTitle -URL $SiteURL -Owner $SiteOwner -StorageQuota $StorageQuota -ResourceQuota $ResourceQuota -Template $SiteTemplate
现在新的网站集将在一分钟内创建!您可以通过转到 SharePoint Online 管理中心进行验证。
PowerShell 使用 CSOM 在 SharePoint Online 中创建新网站集
SharePoint Online 网站集是一组相关网站、网页、文档库和数据管理列表。下面是用于创建新网站集的 SharePoint Online PowerShell。
#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"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
#Set Parameters
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
$NewSiteURL = "https://Crescent.sharepoint.com/Sites/HR"
Try {
#Setup Credentials to connect
$Cred= Get-Credential
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the tenant object
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
Write-Host -f Yellow "Creating site collection..."
#Set the Site Creation Properties
$SiteCreationProperties = New-Object Microsoft.Online.SharePoint.TenantAdministration.SiteCreationProperties
$SiteCreationProperties.Url = $NewSiteURL
$SiteCreationProperties.Template = "STS#0" #Classic site
$SiteCreationProperties.Owner = "[email protected]"
$SiteCreationProperties.StorageMaximumLevel = 1000
$SiteCreationProperties.UserCodeMaximumLevel = 300
#powershell script to create site collection in sharepoint online
$Tenant.CreateSite($SiteCreationProperties) | Out-Null
$ctx.ExecuteQuery()
#Create the site in the tennancy
write-host "Site Collection Created Successfully!" -foregroundcolor Green
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
要从 CSV 文件批量创建多个 SharePoint Online 网站集,请参阅:SharePoint Online:使用 PowerShell 从 CSV 文件批量创建多个网站集
SharePoint Online:PnP PowerShell 创建网站集
如何使用 PowerShell 在 SharePoint Online 中创建新网站集?以下是如何在 SharePoint Online 中使用 PnP PowerShell 创建网站集。您还可以使用 New-PnPSite cmdlet 创建现代团队网站和通信网站。
#Define Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$SiteURL = "https://Crescent.sharepoint.com/sites/procurement"
$SiteTitle = "Crescent Procurement Portal"
$SiteOwner = "[email protected]"
$Template = "STS#3" #Modern SharePoint Team Site
$Timezone = 4
#Get Credentials to connect
$Cred = Get-Credential
Try
{
#Connect to Tenant Admin
Connect-PnPOnline -URL $AdminCenterURL -Credential $Cred
#Check if site exists already
$Site = Get-PnPTenantSite | Where {$_.Url -eq $SiteURL}
If ($Site -eq $null)
{
#sharepoint online pnp powershell create a new team site collection
New-PnPTenantSite -Url $SiteURL -Owner $SiteOwner -Title $SiteTitle -Template $Template -TimeZone $TimeZone -RemoveDeletedSite
write-host "Site Collection $($SiteURL) Created Successfully!" -foregroundcolor Green
}
else
{
write-host "Site $($SiteURL) exists already!" -foregroundcolor Yellow
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
若要在 SharePoint Online 中创建经典团队网站,请使用:SharePoint Online:使用 PowerShell 创建经典网站
经常问的问题:
如何使用 PowerShell 在 SharePoint Online 中创建子网站?
在 SharePoint Online 中创建子网站有几种不同的方法。最简单的方法是使用网络浏览器并创建子网站。您还可以使用 PowerShell 脚本将新子网站添加到 SharePoint Online。
详细信息:如何在 SharePoint Online 中创建子网站?
如何在 SharePoint Online 中创建通信网站?
在 SharePoint Online 中创建通信网站非常简单,只需几分钟即可完成。您可以作为 SharePoint/租户管理员,从 SharePoint 起始页开始通过 Web 浏览器添加新的通信网站,或使用 PowerShell 在 SharePoint Online 中创建通信网站。
详细信息:在 SharePoint Online 中创建通信网站
如何在 SharePoint Online 中添加集合管理员?
若要在 SharePoint Online 中授予网站管理员权限,请使用 PowerShell cmdlet Set-SPOUser 或 PnP PowerShell cmdlet Set-PnPTenantSite。您还可以从 SharePoint 管理中心或网站设置页面添加用户作为集合管理员。
详细信息:在 SharePoint Online 中添加网站集管理员
如何在 SharePoint Online 中创建 Hub 网站?
要在 SharePoint Online 中创建中心网站,请按照下列步骤操作: 导航到 SharePoint Online 管理中心 >> 单击活动网站 >> 选择将成为中心的网站 >> 从中心网站单击“注册为中心网站”菜单。填写中心的名称,然后单击“保存”。您还可以使用 PowerShell 创建中心网站。
详细信息:如何在 SharePoint Online 中创建中心网站?
猜你还喜欢
- 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 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][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
[电视剧] [突围] [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