Sharepoint Online-使用powershell在网站集中列出Sharepoint网站

Sharepoint Online-使用powershell在网站集中列出Sharepoint网站,powershell,sharepoint-online,Powershell,Sharepoint Online,我希望使用powershell在sharepoint online中列出网站集中的所有网站。我目前正在使用以下脚本: 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

我希望使用powershell在sharepoint online中列出网站集中的所有网站。我目前正在使用以下脚本:

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)

有人能帮我吗?

我猜你不是网站集管理员

实施这一改变:

$sites=$rootWeb.GetSubwebsForCurrentUser($null)