0

Introduction to PowerShell for SharePoint Online -2


<#
.SYNOPSIS
Create SharePoint Sites on SharePoint Online

.DESCRIPTION
- This script demonstrated creating sites for SharePoint Online.

--------------------------------------------------------------------------------
Code generated by: Susheel Dakoju., Windows Powershell Host v 3.0
Generated on: 04-12-2015 19:28
Generated by:
Organization:
--------------------------------------------------------------------------------
#>

#SharePoint Online Information
$SharePointOnlineURL = "https://contoso.sharepoint.com/"
$SharePontOnlineAdminSiteURL = "https://contoso-admin.sharepoint.com/"
$AdminUser = "usename@contoso.onmicrosoft.com"

#New Site Information
$newSiteURL = "testsite3"
$newSiteTitle = "testsite3"
$newsiteTemplate = "STS#0"

#--------------------------------------------------------------------
#1. Create SharePoint Online Site
#--------------------------------------------------------------------

#--------------------
# Connect to SharePoint Online Service
#--------------------
Connect-SPOService -Url $SharePontOnlineAdminSiteURL -credential $AdminUser

#Prepare Credentails
$password = Read-Host -Prompt "Enter password" -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SharePointOnlineURL)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminUser, $password)
$ctx.Credentials = $credentials

#Create Web
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = $newSiteURL
$webCreationInformation.Title = $newSiteTitle
$webCreationInformation.WebTemplate = $newsiteTemplate
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)

#Load and Execute
$ctx.Load($newWeb)
$ctx.ExecuteQuery()

Write-Host "Title" $newWeb.Title

#End of Create SharePoint Online Site

Leave a Reply