Creating SharePoint Online Site using PowerShell

A combo of SPO and PnP modules to create SharePoint Online Site and List

Naqash Ahmed
4 min readDec 31, 2021
Courtesy: CodeTwo

One of the oldest and widely used solutions by Microsoft is SharePoint which started in 2001 with products of different categories like Standard, Enterprise, Server Edition and Online. There were and still some side-solutions which have integrations with SharePoint. Today, in this blog we will focus on the SharePoint Online and how you can use PowerShell commands to create a site along with list and list items. These commands will come handy for System Admins or SharePoint Admins to manage their organizational intranet and its applications. We shall be using a mix of Microsoft owned SharePoint PS module and PnP module for cross-platform usability.

  1. First you need SharePoint Online Management Shell to work on the scripts below. If you do not have it, download it from here for free.
  2. Run the SPO Management Shell as SharePoint Admin or Global Administrator and connect to your tenant using below command. Make sure to edit your own tenant admin URL which you can get from SPO Admin Center. This command will also work if you have MFA enabled.
SharePoint Online Management Shell connect command

3. Once inside the SharePoint Online, you can run the below command to create a new site collection using below command. We shall be creating Communication Site as it has more enhanced and rich features.

SharePoint Online create new site

If you are wondering about the template value for Communication Site or any other site that you wish to create, run Get-SPOWebTemplate before to get the template values like you are seeing above.

4. We have our site collection ready at tenant level, now we need to dig into this site collection and create list and list item using PnP module which works at site collection level as current user. If you do not have PnP module installed already, run the below command and then connect to it.

In the Url parameter, use the site collection URL you want to work against. In this example, we will work on our site collection by the name NewDevSite.

SharePoint Online PnP Module

5. Use the below command to create a list first where our data or list items will be stored. I have used the list template as Announcements but you can choose any template listed here

6. Our list “Internal Requests” has been created. Now we shall create two columns in the list for our data to be recorded using below command. Notice the Type parameter which states the type of the column either Text, Date, Person or any other. For this blog, I will create User and DateTime column.

7. Our list has now two columns along with default ones but it is incomplete without any list item. Use the below command to create records as per the column values.

Here is the final look of our list and its items.

SharePoint Online List

There are tons of other commands which you can use to manage SharePoint Online sites and I shall be writing another blog post on managing permissions of a site using PowerShell.

Thank you for reading.

--

--