Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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"

$siteUrl = "https://tenant.sharepoint.com/sites/mysitecollection" $username = "username@tenant.onmicrosoft.com" $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

am i missing something? i'm global administrator for my o365 tenant & sharepoint admin in sharepoint online. still getting this error : Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (403) Forbidden."


What I have tried:

I tried using adding new global administrator user in 0365 and then import him into sharepoint Admin group.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900