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

[玩转系统] 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 网站集,请按照下列步骤操作:

  1. 以租户管理员或 SharePoint Online 管理员权限身份登录 SharePoint 管理中心。
  2. 单击左侧导航中的站点 >> 活动站点 >> 单击“创建”。
  3. 选择“团队网站”选项来创建包含 Office 365 组的现代团队网站集,或选择“其他选项”来创建不包含 Office 365 组的现代团队网站。

    [玩转系统] SharePoint Online:如何使用 PowerShell 创建网站集?

  4. 从 SharePoint 网站模板中,选择网站模板(例如“团队网站”),提供网站名称、网站地址和管理员选项,然后选择语言。单击“高级设置”以设置时区和站点描述。输入所有详细信息并在 SharePoint Online 中创建网站集后,单击“完成”。

    [玩转系统] SharePoint Online:如何使用 PowerShell 创建网站集?

稍等片刻,您的新式 SharePoint 网站集应出现在网站集列表中。

如何从 SharePoint 起始页创建 SharePoint Online 网站?

您还可以使用 SharePoint 主页 (https://tenant.sharepoint.com/_layouts/15/sharepoint.aspx) 创建 SharePoint 网站,只需转到 Office 365 应用程序启动器 >> 单击 SharePoint >> 单击工具栏中的“创建站点”按钮。 (除非 SharePoint 管理员或全局管理员禁用网站创建 - 默认情况下,它是启用的!因此,任何人都可以创建新网站)。

[玩转系统] SharePoint Online:如何使用 PowerShell 创建网站集?

输入站点名称、描述、隐私设置和语言,设置组电子邮件地址,然后单击“下一步>>添加任何组成员以授予站点权限”,然后单击“完成”。这将创建 Microsoft 365 组连接的 SharePoint 网站集。

[玩转系统] SharePoint Online:如何使用 PowerShell 创建网站集?

从 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 创建网站集?

现在,让我们添加一些错误处理并将其包装在可重用函数中,以在 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 中创建中心网站?

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

取消回复欢迎 发表评论:

关灯