Manage SharePoint Online site collections and the web templates with PowerShell

Doctor Scripto

Summary: PowerShell commands can manage site collections and the web templates that create site collections.

Christopher Weaver is a Microsoft Premier Field Engineer (PFE) who focuses on SharePoint and Office 365 solutions for large enterprise Premier customers. He has been doing PowerShell and SharePoint with Microsoft for nine years. In his spare time, he enjoys backpacking, hiking, kite surfing, and spending time with his kids and dog. You can follow him on his blog at https://blogs.technet.microsoft.com/christwe/.

Hello All,

As we prepare our SharePoint Online environment for migration, we will need to be able to manage site collections and the web templates we use to create those site collections.  First, let’s look at the available cmdlets in this category.

Get-SPOWebTemplate – Gets all site templates that are available, or you can get specific templates based on different parameters.  In the example, we get the default Team Site web template.

Result from Get-SPOWebTemplate

Get-SPOWebTemplate -Name STS#0

Get-SPOSite – Gets one or more site collections. You could then take that object and pass it to another cmdlet or use its members.

Result from Get-SPOSite

Get-SPOSite https://mmr258720.sharepoint.com

New-SPOSite – Creates a new site collection. It has many parameters, so you can set several properties automatically at creation time.

Result from New-SPOSite

New-SPOSite -url https://mmr258720.sharepoint.com/sites/test1 -Owner admin@mmr258720.onmicrosoft.com -StorageQuota 26214400

Remove-SPOSite – Moves a site collection to the recycle bin to permanently delete the site collection. Before the site is permanently deleted, you need to run the Remove-SPODeletedSite command or wait approximately 90 days.  During this time, the site collection will not count towards storage quotas.

Result from Remove-SPOSite

Remove-SPOSite https://mmr258720.sharepoint.com/sites/test1

Set-SPOSite – Allows you to set many different properties on an existing site collection.

Result from Set-SPOSite

Set-SPOSite https://mmr258720.sharepoint.com/sites/mr -lockstate NoAccess

Test-SPOSite – This command will run one or several different health rules and then return the results.

This command only produces a report. It does not make any changes to your site.  After you have reviewed the report and are comfortable with the repairs, then please run the Repair-SPOSite cmdlet, which I describe later.

The site health rules are:

Rule name Rule ID
Conflicting Content Types befe203b-a8c0-48c2-b5f0-27c10f9e1622
Customized Files cd839b0d-9707-4950-8fac-f306cb920f6c
Missing Galleries ee967197-ccbe-4c00-88e4-e6fab81145e1
Missing Parent Content Types a9a6769f-7289-4b9f-ae7f-5db4b997d284
Missing Site Templates 5258ccf5-e7d6-4df7-b8ae-12fcc0513ebd
Unsupported Language Pack References 99c946f7-5751-417c-89d3-b9c8bb2d1f66
Unsupported MUI References 6da06aab-c539-4e0d-b111-b1da4408859a

 

Result from Test-SPOSite

Test-SPOSite https://mmr258720.sharepoint.com

Repair-SPOSite – Will run the health tests from the Test-SPOSite command and, when possible, will automatically repair an issue.  After the command finishes running, it will provide a report with results.

Result from Repair-SPOSite

Repair-SPOSite https://mmr258720.sharepoint.com

Upgrade-SPOSite – Performs site collection upgrade. By default, this will be build-to-build upgrade. However, on occasion it could become a version-to-version upgrade. In this case, you must run a health check in repair mode to ensure that the site collection can be upgraded.

Result from Upgrade-SPOSite

Upgrade-SPOSite https://mmr258720.sharepoint.com

As we prepare to migrate, we must create the new site collection that we will be migrating to, so let’s look at the cmdlets that will make this possible. The first cmdlet will be New-SPOSite because this is the command that will create the site collection. Let’s look at the parameters we can use.

NOTE: If a site collection in the Recycle bin has the same URL, this cmdlet will fail with an error that looks like this.

New-SPOSite : A site already exists at url https://tenant.sharepoint.com/sites/sitecollection

The solution is to restore from the Recycle bin or permanently delete the site collection.

  • Url – This is a required parameter and represents the URL for your site collection. Make sure that the managed path is valid for your tenant.
  • Owner – This is a required parameter and represents the user name of the owner. The Owner must be a valid user account in your tenant (This means no groups or distribution lists). The owner receives Full Control of the site collection. This user should receive some high-level training to insure he doesn’t do undesired damage.
  • StorageQuota – This is a required parameter and represents the maximum size in MB that the site collection will grow. This cannot exceed the tenant max and includes items like the Recycle bin.
  • Template – This is an optional parameter, but I recommend that you set it ahead of time. If you don’t set it, the first person to hit the site collection with the correct permissions will get to pick the Template for you. You can pick a valid template by running the Get-SPOWebTemplate
  • CompatibilityLevel – This is an optional parameter but, again, I recommend that you set this ahead of time.

If you have been following my last few articles, you should now be able to connect to the SharePoint Online service, manage the tenant, and manage/create site collections. The next step will be how to use the migration API. Watch for that next.

Ed Wilson Microsoft Scripting Guy

0 comments

Discussion is closed.

Feedback usabilla icon