Share via


CSOM SharePoint Online Create Web Using PowerShell


CSOM SharePoint Online Create Web Using PowerShell


Summary

In this Wiki let's explore PowerShell code for creating Web in SharePoint Online

Help

help about_Methods -Detailed
help about_Variables -Detailed
help Read-Host -Parameter AssecureString
help Add-Type -Detailed
help Import-Module -Detailed

PowerShell Code

 #Import the required DLL
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
#OR
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'

#Mysite URL
$site = 'https://Domain.sharepoint.com/'

#Admin User Principal Name
$admin = 'Admin@Chensoffice365.OnMicrosoft.Com'

#Get Password as secure String
$password = Read-Host 'Enter Password' -AsSecureString

#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

#Create Web
$createWeb = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$createWeb.Url = 'CSOM Web'
$createWeb.Description = 'Created Using PowerShell SharePoint CSOM'
$createWeb.UseSamePermissionsAsParentSite = $true
$createWeb.Title = 'Consume CSOM'
$createWeb.WebTemplate = "STS#0"

$AddWeb = $context.Web.Webs.Add($createWeb)

$context.Load($AddWeb)

$context.ExecuteQuery()

Result

See Also

http://social.technet.microsoft.com/wiki/contents/articles/29531.csom-sharepoint-online-delete-list-using-powershell.aspx