2016-09-05 2 views
0

Я хочу, чтобы список всех сайтов в sitecollection в sharepoint онлайн использовался с помощью powershell. Я использую следующий скрипт в данный момент:Sharepoint Online - перечислить сайты sharepoint в sitecollection с помощью powershell

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://mytenant.sharepoint.com/sites/mysitecollection” 
$username = "myusername" 
$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 

$rootWeb = $ctx.Web 
$sites = $rootWeb.Webs 

$ctx.Load($rootWeb) 
$ctx.Load($sites) 
$ctx.ExecuteQuery() 

foreach($site in $sites) 
{ 
    $ctx.Load($site) 
    $ctx.ExecuteQuery() 

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

Ошибки выглядеть следующим образом:

Exception calling " executeQuery " with 0 Argument (s) : " The remote server returned an error : (401) Unauthorized . " 
Line : 16 Char: 1 

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. 
In Zeile:18 Zeichen:9 
+ foreach($site in $sites) 

Может кто-нибудь помочь мне, пожалуйста?

ответ

0

Я предполагаю, что вы не администратор семейства сайтов.

Реализовать это изменение:

$sites = $rootWeb.GetSubwebsForCurrentUser($null)

Смежные вопросы