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/.
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.
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.
New-SPOSite – Creates a new site collection. It has many parameters, so you can set several properties automatically at creation time.
New-SPOSite -url https://mmr258720.sharepoint.com/sites/test1 -Owner email@example.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.
Set-SPOSite – Allows you to set many different properties on an existing site collection.
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|
|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|
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.
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.
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.
Microsoft Scripting Guy