Monday, July 14, 2014

Power-shell Script to Create the Site on Online SharePoint 2013

Hi All,
      I got a requirement to create the site on online sharepoint 2013 through Power shell script .But before moving further you need to download the CSOM  SharePoint Server 2013 Client Components SDK.  and Online SharePoint 2013 Powershell . And replace given url in  "$siteurl " and name in "$username"  by entering password when it prompts on executing the command "$password = Read-Host -Prompt "Enter password" -AsSecureString" .


Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"



$password = Read-Host -Prompt "Enter password" -AsSecureString

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$password)

$ctx.Credentials = $credentials

$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation

$webCreationInformation.Url = "site1"

$webCreationInformation.Title = "Site 1"

$webCreationInformation.WebTemplate = "STS#0"

$newWeb = $ctx.Web.Webs.Add($webCreationInformation)

$ctx.Load($newWeb)

$ctx.ExecuteQuery()

Write-Host "Title" $newWeb.Title


Write-Host $site.Title "-" $site.Url