Quantcast
Viewing all articles
Browse latest Browse all 10096

SharePoint Online - Load Subsite via CSOM Powershell

Hi All,

I'm trying to load a subsite via CSOM Powershell, using the SharePoint Online Client Components SDK.

However, my site collection is using a managed path (teams):

https://tenant.sharepoint.com/teams/sitecollection

I want to create groups and add them to a subsite with unique permissions.

https://tenant.sharepoint.com/teams/sitecollection/testsubsite

Could anyone explain, what I'm doing wrong? $web1 is loading the root site collection fine. $web2 is not loading correctly.

Exception calling "ExecuteQuery" with "0" argument(s): "Invalid URL: /testsubsite."

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

$WebURL = "https://tenant.sharepoint.com/teams/sitecollection"

if($Script:Credential -eq $null) {
$Credentials = Get-Credential -Message "SharePoint Online Credential"
$Script:Credential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credentials.UserName , $Credentials.Password)
$SPOClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
$SPOClientContext.Credentials = $Credential;
}

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
$ctx.Credentials = $Credential

$web1 = $ctx.Site.RootWeb
$ctx.Load($web1)
$ctx.ExecuteQuery()

$web2 = $ctx.Site.OpenWeb("/testsubsite")
$ctx.Load($web2)
$ctx.ExecuteQuery()

Regards,

Christian


Viewing all articles
Browse latest Browse all 10096

Trending Articles