SP2013_logo

Create and Delete Sites in SharePoint 2013 Online with PowerShell

In this post I describe how to connect to SharePoint 2013 Online using PowerShell and how to create and delete team sites there.

Download SharePoint Online Management Shell
It is recommended that the SharePoint Online Management Shell is installed on your system. The preview edition can be downloaded from here:
http://www.microsoft.com/en-us/download/details.aspx?id=30359

Connect to Service
First of all, it is neccessary to establish a connection to SharePoint Online. Important her is to pass in the URL to the admin site collection. Other URLs won’t work. This command will establish the connection, the password will be asked by a dialogue as you run the command:

Connect-SPOService -Url https://yourdomain.sharepoint.com -Credential your.mail@yourdomain.onmicrosoft.com

spo_powershell1

The following commands allows to bypass the dialogue by passing in of a password within the script:

$credentials = New-Object -TypeName System.Management.Au
tomation.PSCredential -ArgumentList "your.mail@yourdomain.onmicrosoft.
com", $(ConvertTo-SecureString "yourpassword" -AsPlainText -Force)

Connect-SPOService -Url https://yourdomain-admin.sharepoint.com -Credential $credentials

Now there is a connection established with SharePoint Online. You can test your connection by getting information about your site using this command:

Get-SPOSite -Identity https://yourdomain.sharepoint.com

Create a new Site
The following command will create a new teamsite under the path “/sites/teamsitecollection2″:

New-SPOSite -Url https://yourdomain.sharepoint.com/sites/teamsitecollection2 -Owner your.mail@yourdomain.onmicrosoft.com -StorageQuota 500 -ResourceQuota 50  -Title "Created by PowerShell" -Template STS#0

The script may take some time to finish. To continue with your script without waiting for SharePoint Online, add the parameter “-NoWait”.

The creation status can be watched in the admin area of SharePoint Online:
https://yourdomain-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx

spo_powershell2

Delete a Site
With the following the site created above will be deleted and moved to the recycle bin:

Remove-SPOSite -Identity https://yourdomain.sharepoint.com/sites/teamsitecollection2

spo_powershell3

The following command removes the site collection from the recycle bin:

Remove-SPODeletedSite -Identity https://yourdomain.sharepoint.com/sites/teamsitecollection2

Is there a use case for this?
In my opinion these snippets will help in an environment where On-Premise and Cloud shall be used in hybrid mode. If a team site needs to be accessed by external users then it is neccessary to create this site in SharePoint Online.

Read more
Windows PowerShell for SharePoint Online reference
http://technet.microsoft.com/en-us/library/fp161397.aspx

About these ads

One Response to “Create and Delete Sites in SharePoint 2013 Online with PowerShell”

  1. Wonderful Article..
    Helped a lot.

    Also wanted to know the manual method of deleting SPO site from Recycle-Bin of the Site collection.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: