プログラムを使用した "モダン" チーム サイトのプロビジョニング

2016 年秋に "モダン" サイトが SharePoint Online に導入されました。それらを使用するオプションをテナント レベルで制御できます。 この記事では、SharePoint Online での "モダン" サイトをプロビジョニングするためのさまざまなオプションや考慮事項について取り上げます。 この記事では特に "モダン" チーム サイトと "モダン" コミュニケーション サイトの作成方法について説明しています。

重要

"クラシック" エクスペリエンスは廃止されていません。"クラシック" と "モダン" の両方が共存しています。

"モダン" チーム サイトと "モダン" コミュニケーション サイトの比較

"モダン" サイトのプロビジョニング方法を詳しく掘り下げる前に、2 つの主な種類 (チーム サイトとコミュニケーション サイト) について簡単に説明します。

"モダン" チーム サイトは、グループのメンバーが同時作業、共同作業、およびドキュメントやメッセージの共有を行うことができる場所です。 すべての "モダン" チーム サイトでは Microsoft 365 グループにより、全体的なコラボレーション エクスペリエンスが向上します。 つまり、Microsoft 365 グループのおかげで、チームのメンバーは Planner、共有カレンダー、共有 OneDrive for Business ストレージ、カスタム Office 365 コネクタなどのサービスを利用できます。 "モダン" チーム サイトでは通常、メンバーがコンテンツに投稿できます (読み取り/書き込み)。 さらに、Microsoft 365 グループでは "モダン" チーム サイトを非公開または公開にすることができ、既定では公開になっています。

"モダン" コミュニケーション サイトは、ニュースの共有、ストーリーの紹介、またはメッセージの配信が可能な場所です。 コミュニケーション サイトという概念は、数名の編集者がコンテンツを作成、保持し、多数の配信対象者がそのコンテンツを利用することを意味します。 ただし、コミュニケーション サイトでは Microsoft 365 グループは使用されていません。 ユーザーはその他の SharePoint サイトでよく知られているアクセス許可を使用して対象のコミュニケーション サイトにアクセスできますが、既定ではすべてのコミュニケーション サイトは非公開です。

このため、チーム コラボレーションのためのサイトを作成する必要がある場合、"モダン" チームサイトが最も適しています。 反対に、幅広いユーザーとコミュニケーションをとる必要がある場合には、コミュニケーション サイトの方が適しています。

"モダン" チーム サイトのプロビジョニング

このセクションでは、"モダン" チーム サイトをプロビジョニングする方法と、そのために利用できるオプションについて説明します。

ユーザー インターフェイスからの "モダン" チーム サイトのプロビジョニング

"モダン" チーム サイトをプロビジョニングする方法は多数あります。 SharePoint Online サイトから直接プロビジョニングを開始することも、他の場所から (たとえば Outlook から) Microsoft 365 グループをプロビジョニングして、"モダン" チーム サイトのプロビジョニングをトリガーさせることもできます。

  • 管理者がテナントで "モダン" チーム サイトを有効にした場合、SharePoint の開始ページから "モダン" チーム サイトを作成することができます。

  • Office 365 Outlook から Microsoft 365 グループを作成することもでき、そのグループの [サイト] タブにアクセスすると、"モダン" チーム サイトにたどり着きます。

既定のプロビジョニング フローを制御する

SharePoint Online の管理設定から、SharePoint のサイト作成プロセスを制御できます。 エンド ユーザーが "モダン" エクスペリエンスを使用できるようにするか、"クラシック" エクスペリエンスを使用し続けるかを選択できます。

SharePoint Online 管理者 UI からのサイト作成のオプション

詳細については、次の Office サポート記事を参照してください。

SharePoint Online REST API でプログラムを使用した "モダン" チーム サイトのプロビジョニング

"モダン" チーム サイトを作成するには、SharePoint Online にある REST API でプログラムを使用することも、SharePoint Online の [サイトの作成] UI を使用することもできます。 REST 経由で "モダン" チーム サイトをプロビジョニングするには、Microsoft Graph の "groups" エンドポイントへの POST リクエストを行います。https://graph.microsoft.com/v1.0/groups

"モダン" チーム サイトの URI は mailNickname パラメーターと、テナント管理でチーム サイト用に選択した管理パスで決まります (この既定値は 'sites' です)。

次の例では、Microsoft 365 グループと、関連付けられている、次の URL を持つ "モダン" チーム サイトを作成します。https://[tenant].sharepoint.com/sites/mymodernteamsite

POST https://graph.microsoft.com/v1.0/groups
Content-type: application/json
Content-length: 200

{
  "description": "description",
  "displayName": "My modern team site",
  "groupTypes": [
    "Unified"
  ],
  "mailEnabled": true,
  "mailNickname": "mymodernteamsite",
  "securityEnabled": false
}

PnP CSOM コア コンポーネントを使用した "モダン" チーム サイトのプロビジョニング

SharePoint PnP Core コンポーネントでは、2017 年 10 月リリース (v. 2.19.1710.1) 以降、CSOM ClientContext 型の新しい拡張メソッドがあります。 この拡張メソッド名は CreateSiteAsync であり、"モダン" チーム サイトをわずか数秒で作成することができます。

次のコード スニペットでは、この技法の使用方法を確認できます。

// Let's use the CreateSiteAsync extension method of PnP CSOM Core
// to create the "modern" team site

var targetTenantUrl = "https://[tenant].sharepoint.com/";

using (var context = new ClientContext(targetTenantUrl))
{
    context.Credentials = OfficeDevPnP.Core.Utilities.CredentialManager.GetSharePointOnlineCredential("[Name-of-Your-Credentials]");

    // Create new "modern" team site at the url
    // https://[tenant].sharepoint.com/sites/mymodernteamsite
    var teamContext = await context.CreateSiteAsync(
        new TeamSiteCollectionCreationInformation
        {
            Alias = "mymodernteamsite", // Mandatory
            DisplayName = "displayName", // Mandatory
            Description = "description", // Optional
            Classification = "classification", // Optional
            IsPublic = true, // Optional, default true
        });
    teamContext.Load(teamContext.Web, w => w.Url);
    teamContext.ExecuteQueryRetry();
    Console.WriteLine(teamContext.Web.Url);
}

注:

Classification 引数の詳細については、SharePoint "モダン" サイトの分類を参照してください。

ご覧のとおり、拡張メソッドが新しい "モダン" チーム サイトを作成し、この新しく作成されたサイトに直接接続された新しい ClientContext オブジェクトを返します。

PnP PowerShell を使用した "モダン" チーム サイトのプロビジョニング

PnP PowerShell を使用して "モダン" チーム サイトを作成することもできます。 次のスクリプトは、"モダン" チーム サイトを作成し、その後の操作のために実際の SharePoint サイトの URL を返します。 作成されたサイトの URL へのアクセスを得た後、(SharePoint PnP コア コンポーネントの) CSOM または SharePoint PnP-PowerShell を使用して、作成されたサイト上の他の操作を自動化することができます。

# Connect to SharePoint Online
# This command will prompt the sign-in UI to authenticate
Connect-PnPOnline "https://[tenant].sharepoint.com/"

# Create the new "modern" team site
$teamSiteUrl = New-PnPSite -Type TeamSite -Title "displayName" -Alias "mymodernteamsite" -Description "description" -IsPublic -Classification "classification" 

# Connect to the modern site using PnP PowerShell SP cmdlets
# Since we are connecting now to SP side, credentials will be asked
Connect-PnPOnline $teamSiteUrl

# Now we have access on the SharePoint site for any operations
$web = Get-PnPWeb -Includes WebTemplate, Configuration
$web.WebTemplate + "#" + $web.Configuration

注:

PnP PowerShell はオープン ソース ソリューションであり、アクティブなコミュニティでサポートが提供されています。 Microsoft からのオープン ソース ツールのサポート SLA はありません。

CLI for Microsoft 365を使用した「モダン」チームサイトのプロビジョニング

また、CLI for Microsoft 365 を使用して、"モダン" サイトを作成することもできます。 CLI for Microsoft 365 は、Windows、MacOS、Linux などのあらゆるプラットフォームで使用できるクロスプラットフォーム コマンド ライン インターフェイスです。

注:

CLI for Microsoft 365 はオープン ソース ソリューションであり、アクティブなコミュニティでサポートが提供されています。 Microsoft からのオープン ソース ツールのサポート SLA はありません。

次の Bash スクリプトは、"モダン" チーム サイトを作成し、その後の操作のために実際の SharePoint サイトの URL を返します。 作成したサイトの URL にアクセスすると、それを使用して作成したサイトのその他の操作を自動化することができます。

#!/usr/bin/env bash
# Connect to Microsoft 365 tenant
# This command will prompt a sign-in confirmation message to authenticate
m365 login

# Create the new "modern" team site
siteUrl=$(m365 spo site add --type TeamSite --title 'displayName' --alias 'mymodernteamsite' --description 'description' --isPublic --classification 'classification')

# Display the modern site url
echo $siteUrl

# Since the CLI for Microsoft 365 is connected to Microsoft 365 tenant we can do any operations. 
# As example, we can list all the properties from the site property bag:
m365 spo propertybag list -u $siteUrl

プログラムを使用した Microsoft 365 グループのプロビジョニング

Microsoft Graph を使用してMicrosoft 365 グループ を作成することにより、プログラムで "モダン" チーム サイトを作成することができます。 つまり、Microsoft 365 グループを作成すると、グループ用の "モダン" チーム サイトが自動的にプロビジョニングされます。 "モダン" チーム サイト URI は Microsoft 365 グループの mailNickname パラメーターに基づいたもので、既定の構造は次のとおりです。

https://[tenant].sharepoint.com/sites/[mailNickname]

注:

Microsoft Graph を使用したグループ作成の解説は、公式ドキュメントから入手できます。

PnP CSOM コア コンポーネントを使用した Microsoft 365 グループのプロビジョニング

NuGet パッケージとして利用可能な PnP CSOM コア コンポーネントでは、"モダン" グループを扱う方法が単純化されました。

/// <summary>
/// Let's use the UnifiedGroupsUtility class from PnP CSOM Core to simplify managed code operations for Microsoft 365 groups
/// </summary>
/// <param name="accessToken">Azure AD Access token with Group.ReadWrite.All permission</param>
public static void ManipulateModernTeamSite(string accessToken)
{
    // Create new modern team site at the url https://[tenant].sharepoint.com/sites/mymodernteamsite
    Stream groupLogoStream = new FileStream("C:\\groupassets\\logo-original.png", 
                                            FileMode.Open, FileAccess.Read);
    var group = UnifiedGroupsUtility.CreateUnifiedGroup("displayName", "description", 
                            "mymodernteamsite", accessToken, groupLogo: groupLogoStream);
            
    // We received a group entity containing information about the group
    string url = group.SiteUrl;
    string groupId = group.GroupId;

    // Get group based on groupID
    var group2 = UnifiedGroupsUtility.GetUnifiedGroup(groupId, accessToken);
    // Get SharePoint site URL from group id
    var siteUrl = UnifiedGroupsUtility.GetUnifiedGroupSiteUrl(groupId, accessToken);

    // Get all groups in the tenant
    List<UnifiedGroupEntity> groups = UnifiedGroupsUtility.ListUnifiedGroups(accessToken);

    // Update description and group logo programatically
    groupLogoStream = new FileStream("C:\\groupassets\\logo-new.png", FileMode.Open, FileAccess.Read);
    UnifiedGroupsUtility.UpdateUnifiedGroup(groupId, accessToken, description: "Updated description", 
                                            groupLogo: groupLogoStream);

    // Delete group programatically
    UnifiedGroupsUtility.DeleteUnifiedGroup(groupId, accessToken);
}

PnP PowerShell を使用した Microsoft 365 グループのプロビジョニング

PnP PowerShell を使用して Microsoft 365 グループを作成することもでき、Azure Active Directory を使用した Microsoft Graph で認証を簡単に行えます。 次のスクリプトは、"モダン" チーム サイトとともに Microsoft 365 グループを作成し、後続の操作のために実際の SharePoint サイト URL を返します。 作成されたサイトの URL へのアクセスを得た後、(SharePoint PnP コア コンポーネントの) CSOM または SharePoint PnP-PowerShell を使用して、作成されたサイト上の他の操作を自動化することができます。

# Connect to your SharePoint admin center, credentials will be asked
Connect-PnPOnline -Url https://contoso-admin.sharepoint.com

# Create a new modern team site
New-PnPSite -Type Team -Title "Awesome Group" -Description "Awesome Group" -Alias "awesome-group"

SharePoint Online 管理シェルまたは PnP PowerShell を使用してモダン チーム サイトをプロビジョニングする

PowerShell を使用して、グループに接続されていないモダン サイトを作成することも可能です。 PnP PowerShell コマンドレットまたは SharePoint Online 管理シェルのいずれかを使用します。

$title = "Awesome ModernTeamsite"
$url = "https://contoso.sharepoint.com/sites/awesomemodernteamsite"
$owner = "denisd@contoso.com"

// SharePoint Online Management Shell
New-SPOSite -Title $_title -Url $_url -Owner $owner -StorageQuota 512 -Template "STS#3"

// PnP
New-PnPTenantSite -Url $_url -Description $_title -Title $_title -Template STS#3 -Owner $owner

CLI for Microsoft 365を使用して、Microsoft 365のグループのプロビジョニング

また、CLI for Microsoft 365 を使用して、Microsoft 365グループを作成することもできます。

#!/usr/bin/env bash
# Connect to Microsoft 365 tenant
# This command will prompt a sign-in confirmation message to authenticate
m365 login

# Create a Microsoft 365 group
# The newly created SharePoint site for that group will have the URL
# https://[tenant].sharepoint.com/sites/awesome-group
m365 aad o365group add --displayName 'Awesome Group' --description 'Awesome Group' --mailNickname awesome-group

"モダン" コミュニケーション サイトのプロビジョニング

このセクションでは、"モダン" コミュニケーション サイトをプロビジョニングする方法と、そのために利用できるオプションについて説明します。

ユーザー インターフェイスからの"モダン" コミュニケーション サイトのプロビジョニング

ユーザー インターフェイスを使用して "モダン" コミュニケーション サイトをプロビジョニングするには (管理者がテナントで "モダン" チーム サイトを有効にした場合)、SharePoint Online ホーム ページから直接開始できます。 [サイトの作成] ボタンをクリックして、コミュニケーション サイトの作成を選択し、サイトのデザインを選んで名前と説明を入力すると、わずか数秒でサイトが作成されます。

現時点で利用できるコミュニケーション サイトのデザインは次のとおりです。

  • トピック: ニュース、イベントやその他のコンテンツなど、共有する情報が多数ある場合はこのデザインを使用します。
  • ショーケース: このデザインでは、写真や画像を使用して製品、チーム、イベントを紹介します。
  • 空白: 空白のサイトから、自分のデザインをすばやく簡単に完成させます。

プログラムを使用した "モダン" コミュニケーション サイトのプロビジョニング

このほかに、CSOM と PnP、または PowerShell でプログラムを使用して "モダン" コミュニケーション サイトを作成することもできます。

PnP CSOM コア コンポーネントを使用した" モダン" コミュニケーション サイトのプロビジョニング

NuGet パッケージとして利用可能な PnP CSOM コア コンポーネントでは、"モダン" サイトを扱う方法が単純化されました。

// Let's use the CreateSiteAsync extension method of PnP CSOM Core
// to create the "modern" team site

var targetTenantUrl = "https://[tenant].sharepoint.com/";

using (var context = new ClientContext(targetTenantUrl))
{
    context.Credentials = OfficeDevPnP.Core.Utilities.CredentialManager.GetSharePointOnlineCredential("[Name-of-Your-Credentials]");

    // Create new "modern" communication site at the url https://[tenant].sharepoint.com/sites/mymoderncommunicationsite
    var communicationContext = await context.CreateSiteAsync(new CommunicationSiteCollectionCreationInformation {
        Title = "title", // Mandatory
        Description = "description", // Mandatory
        Lcid = 1033, // Mandatory
        AllowFileSharingForGuestUsers = false, // Optional
        Classification = "classification", // Optional
        SiteDesign = CommunicationSiteDesign.Topic, // Mandatory
        Url = "https://[tenant].sharepoint.com/sites/mymoderncommunicationsite", // Mandatory
    });
    communicationContext.Load(communicationContext.Web, w => w.Url);
    communicationContext.ExecuteQueryRetry();
    Console.WriteLine(communicationContext.Web.Url);
}

ご覧のとおり、拡張メソッドが新しい "モダン" コミュニケーション サイトを作成し、この新しく作成されたサイトに直接接続された新しい ClientContext オブジェクトを返します。

PnP PowerShell を使用した "モダン" コミュニケーション サイトのプロビジョニング

"モダン" チーム サイトの例と同様に、次のスクリプトは、"モダン" コミュニケーション サイトを作成し、後続の操作のために実際の SharePoint サイト URL を返します。

# Connect to SharePoint Online
# This command will prompt the sign-in UI to authenticate
Connect-PnPOnline "https://[tenant].sharepoint.com/"

# Create the new "modern" communication site
$communicationSiteUrl = New-PnPSite -Type CommunicationSite -Title "displayName" -Url "https://[tenant].sharepoint.com/sites/mymoderncommunicationsite" -Description "description" -Classification "classification" -SiteDesign Topic

# Connect to the modern site using PnP PowerShell SP cmdlets
# Since we are connecting now to SP side, credentials will be asked
Connect-PnPOnline $communicationSiteUrl

# Now we have access on the SharePoint site for any operations
$context = Get-PnPContext
$web = Get-PnPWeb
$context.Load($web, $web.Title)
Execute-PnPQuery
$web.Title

Office 365 CLI を使用した "モダン" コミュニケーション サイトのプロビジョニング

また、CLI for Microsoft 365 を使用して、"モダン" コミュニケーションサイトを作成することもできます。 次の Bash スクリプトは、サイトを作成し、その後の操作のために実際の SharePoint サイトの URL を返します。 URL にアクセスすると、それを使用して作成したサイトのその他の操作を自動化することができます。

#!/usr/bin/env bash
# Connect to Microsoft 365 tenant
# This command will prompt a sign-in confirmation message to authenticate
m365 login

# Create the new "modern" communication site
siteUrl=$(m365 spo site add --type CommunicationSite --url https://[tenant].sharepoint.com/sites/mymoderncommunicationsite --title displayName --description description --classification classification)

# Display the modern site url
echo $siteUrl

# Since the CLI for Microsoft 365 is connected to your Microsoft 365 tenant we can do any operations. 
# As example, we can list all the properties from the site property bag:
m365 spo propertybag list -u $siteUrl

その他の考慮事項

サブサイトは "クラシック" テンプレートを使用する

"モダン" サイト コレクションのルート サイトのサブサイトをプロビジョニングする場合、サブサイトは "クラシック" テンプレートを使用します。 現在、利用可能な "モダン" サブサイト テンプレートはありません。 サイトに "モダン" ページを作成し、ウェルカム ページを新しく作成したページに更新することによって、"クラシック" サブサイトを "モダン" チーム サイトに変換できます。

ユーザーが "モダン" サイト コレクションの下に"クラシック" サブサイトを作成できないようにするには、管理者として SharePoint 管理センターに進み、[設定] ページを選択肢して [サブサイトの作成] のオプションを構成して [サブサイト] 作成メニューを非表示にします。 次の図は、[サブサイトの作成] オプションを示しています。

SharePoint Online 管理者 UI からのサブサイト作成のオプション

サイトは、クラシックの SharePoint 管理者 UI/テナント API の一覧には表示されません。

"モダン" チーム サイトは、SharePoint 管理者 UI では表示されません。 Office 365 管理ポータルの Microsoft 365 グループ管理ユーザー インターフェイスから、"モダン" チーム サイトの一覧にアクセスできます。 SharePoint Online 管理ユーザー インターフェイスは、"クラシック" SharePoint サイトのみを一覧表示します。 テナント API には、この同じ制限が適用されません。そのため、この API を使用して、"クラシック"チーム サイトと共に "モダン" チーム サイトを列挙できます。 "モダン" チーム サイトのみの一覧を取得するには、Microsoft Graph API のグループ エンド ポイントを使用することもできます。

また、新しい "モダン" サイト コレクションと、"クラシック" サイト コレクションの両方を管理できる SharePoint 管理者 UI も今後サポートされる予定です。

関連項目