如何使用 PowerShell 在 SharePoint 中创建子网站?
虽然可以从 SharePoint Web UI 轻松管理创建子网站,但我们还可以使用 PowerShell cmdlet New-SPWeb 在 SharePoint 中以编程方式创建子网站。当您必须在任何 SharePoint 2010/2013 网站集下创建一堆子网站时,或者当您必须批量创建子网站时,或者当 SharePoint UI 不提供创建带有“空白”的网站的选项时,这非常有用模板!
使用 PowerShell 在 SharePoint 中创建子网站
您是否正在寻找使用 PowerShell 在 SharePoint 中创建新子网站的方法?这篇博文将向您展示如何使用 PowerShell 在 SharePoint 中创建子网站。我们还将向您展示如何配置子网站的特定设置,例如其标题和描述。
Add-PSSnapin "Microsoft.SharePoint.Powershell" -EA SilentlyContinue
#Define value for Variables
$SiteTitle = "Human Resource"
#URL for you new subsite
$SiteUrl = "https://demo.pccs.com/hr/"
#Templte to be assigned to the subsite
$WebTemplate = "STS#0" #Team Site template
#create subsite using powershell sharepoint 2010/SharePoint 2013
New-SPWeb -Name $SiteTitle -Url $SiteUrl -Template $WebTemplate
成功创建子网站后,New-SPWeb cmdlet 应返回子网站 URL,如上面的屏幕所示。
如果未给 Template 参数指定值,SharePoint 将在您首次打开子网站时提示您选择 Web 模板。虽然上面的脚本只是提供了一种使用 PowerShell 创建子网站的更简单方法,但让我们探索一下使用 PowerShell 在 SharePoint 2013 中创建子网站时的其他选项,例如权限、导航等:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables for site creation
$SiteTitle = "Purchase Portal"
#Site description
$SiteDescription ="Portal for Purchase Department Portal"
#URL for you new subsite
$SiteUrl = "https://intranet.crescent.com/travel/"
#Templte to be assigned to the subsite
$WebTemplate = "STS#0" #Team Site template
# AddToTopNav - Adds the new site within the top navigation of the site collection
# UseParentTopNav - Replicates the top navigation of the site collection into the new subsite
# UniquePermissions - Instructs not to inherit permissions from the site collection
#create subsite using PowerShell SharePoint 2010/SharePoint 2013
New-SPWeb -Name $SiteTitle -Description $SiteDescription -Url $SiteUrl -Template $WebTemplate -AddToTopNav -UniquePermissions -UseParentTopNav
相关文章:SharePoint PowerShell 从模板 SharePoint 2013 创建新子网站 从模板 PowerShell 创建子网站
