I have online sharepoint 2013 subscription and my task is to create one sharepoint site using powerhsell. I have downloaded the Powers-hell for Online sharepoint 2013 for doing power-shell scripting ,But unable to move further. Can any one help me how can I achieve this
1 Answer
The below Powershell script will send the request to SharePoint and your site will be created. Running the script won’t yield any output.
Add-Type -Path "c:\folder\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\folder\Microsoft.SharePoint.Client.Runtime.dll"
$siteUrl = “https://mytenant.sharepoint.com/sites/mysitecollection”
$username = "[email protected]"
$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()
$newWeb
Write-Host "Title" $newWeb.Title
-
Hi Kartik thanks for your code.But can you please help me how can I run the entire code into 1 line– MSAJul 14, 2014 at 9:48
-
@mdsiddiqali, kindly have a look at this link, sharepoint.stackexchange.com/questions/55526/… Jul 14, 2014 at 9:53
-
HI Kartik , At "$ctx.ExecuteQuery()" I am getting error as below "Exception Calling "ExecuteQuery" with "0" arguments(s): "The remote server returned an error: (403) Forbidden." +$ctx.ExecuteQuery() +CategoryInfo :NotSpecified: (:) [],MethodInvocationException +FullyQualifiedErrorId :WebException" . Can you please help me why I am facing this issue and how can I solve this– MSAJul 14, 2014 at 10:14
-
have a look at the below links, stackoverflow.com/questions/18342533/…, blog.blumenthalit.com/blog/Lists/Posts/Post.aspx?ID=171 Jul 14, 2014 at 10:48
-
Are the Credentials provided are proper, does the provided Credentials has required permission to create site.? Jul 14, 2014 at 10:49