Skip to content

Extends the docs on creating modern team sites using the Office365 CLI #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ Execute-PnPQuery
$web.WebTemplate + "#" + $web.Configuration
```

### Provision a "modern" team site using the Office 365 CLI

Alternatively, the [Office 365 CLI](https://sharepoint.github.io/office365-cli/?utm_source=msft_docs&utm_medium=page&utm_campaign=Provisioning+modern+team+sites+programmatically) can be used to create "modern" sites. The Office 365 CLI is a cross-platform command line interface that can be used on any platform, including Windows, MacOS and Linux.

The following bash script will create a "modern" team site and then return the actual SharePoint site URL for further manipulation. Once you have access to the URL of the created site, you can use it to automate other operations on the created site.

```bash
#!/usr/bin/env bash
# Connect to SharePoint Online
# This command will prompt a sign-in confirmation message to authenticate
o365 spo connect https://[tenant].sharepoint.com/

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

# Display the modern site url
echo $siteUrl

# Since the Office 365 CLI is connected to SharePoint Online we can do any operations.
# As example, we can list all the properties from the site property bag:
o365 spo propertybag list -u $siteUrl
```

### Provision an Office 365 group programmatically

"Modern" team sites can be created programmatically by creating an [Office 365 group](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/group) using the Microsoft Graph. In fact, when you create an Office 365 group, a "modern" team site is automatically provisioned for the group. The "modern" team site URI is based on the **mailNickname** parameter of the Office 365 group and has the following default structure.
Expand Down Expand Up @@ -169,9 +192,10 @@ 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"
```

#### Provision a modern teamsite using SharePoint Online Management Shell or PnP PowerShell

It is now also possible to create a modern site which is not connected to a Group using PowerShell. Either by using the PnP PowerShell cmdlets or the SharePoint Online Management Shell.
It is also possible to create a modern site which is not connected to a Group using PowerShell. Either by using the PnP PowerShell cmdlets or the SharePoint Online Management Shell.

```powershell
$title = "Awesome ModernTeamsite"
Expand All @@ -185,6 +209,24 @@ New-SPOSite -Title $_title -Url $_url -Owner $owner -StorageQuota 512 -Template
New-PnPTenantSite -Url $_url -Description $_title -Title $_title -Template STS#3 -Owner $owner
```

#### Provision an Office 365 Group using the Office 365 CLI

Alternatively, the [Office 365 CLI](https://sharepoint.github.io/office365-cli/cmd/graph/o365group/o365group-add/?utm_source=msft_docs&utm_medium=page&utm_campaign=Provisioning+modern+team+sites+programmatically) can be used to create an Office 365 Group, which will let you easily authenticate with the Microsoft Graph and then create the new group.
The example below shows how it can be done using the [Office 365 CLI immersive mode](https://sharepoint.github.io/office365-cli/user-guide/using-cli/#start-the-cli-in-the-immersive-mode?utm_source=msft_docs&utm_medium=page&utm_campaign=Provisioning+modern+team+sites+programmatically).

```bash
# Use the Office 365 CLI immersive mode by typing o365 in the terminal
# Connect to Microsoft Graph using the Office 365 CLI
# This command will prompt a sign-in confirmation message to authenticate
graph connect

# Create an Office 365 Group
# The newly created SharePoint site for that group will has URL
# https://[tenant].sharepoint.com/sites/awesome-group
graph o365group add --displayName 'Awesome Group' --description 'Awesome Group' --mailNickname awesome-group
```


## Provisioning "modern" communication sites

In this section, you learn how to provision a "modern" communication site, and what are the available options to do that.
Expand Down Expand Up @@ -258,6 +300,27 @@ Execute-PnPQuery
$web.Title
```

#### Provision a "modern" communication site using the Office 365 CLI

Alternatively, the [Office 365 CLI](https://sharepoint.github.io/office365-cli/cmd/spo/site/site-add/?utm_source=msft_docs&utm_medium=page&utm_campaign=Provisioning+modern+team+sites+programmatically) can be used to create "modern" Communication site. The following bash script will create the site and then return the actual SharePoint site URL for further manipulation. Once you have access to the URL you can use it to automate other operations on the created site.

```bash
#!/usr/bin/env bash
# Connect to SharePoint Online
# This command will prompt a sign-in confirmation message to authenticate
o365 spo connect https://[tenant].sharepoint.com/

# Create the new "modern" communication site
siteUrl=$(o365 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 Office 365 CLI is connected to SharePoint Online we can do any operations.
# As example, we can list all the properties from the site property bag:
o365 spo propertybag list -u $siteUrl
```

## Additional considerations

### Subsites use "classic" templates
Expand Down