Powershell无法获取SharePoint联机列表

Powershell无法获取SharePoint联机列表,powershell,sharepoint-online,Powershell,Sharepoint Online,我正在尝试编写一个用于自动VM备份的脚本,您也可以在SharePoint Online中手动启动该脚本。我计划在SharePoint中保留一个包含虚拟机名称的列表,并希望通过获取虚拟机列表开始编写脚本。到目前为止,我认为我的代码看起来不错,但是当我想按标题获取列表时,它什么也不返回。 代码如下: [Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePo

我正在尝试编写一个用于自动VM备份的脚本,您也可以在SharePoint Online中手动启动该脚本。我计划在SharePoint中保留一个包含虚拟机名称的列表,并希望通过获取虚拟机列表开始编写脚本。到目前为止,我认为我的代码看起来不错,但是当我想按标题获取列表时,它什么也不返回。 代码如下:

[Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location))
[Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location))


Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context
}

Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
    $list = $Context.Web.Lists.GetByTitle($listTitle)
    $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $items = $list.GetItems($qry)
    $Context.Load($items)
    $Context.ExecuteQuery()
    return $items 
}

$UserName = read-host "Please enter your name:"
$PasswordReadHost = Read-Host -Prompt "Enter password" -AsSecureString  
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($PasswordReadHost))
$Url = "https://domain.sharepoint.com/"
$ListTitle = "VMList"
$context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
$items = Get-ListItems -Context $context -ListTitle $ListTitle
当我运行此操作时,在末尾添加一个断点并检查
$list
变量的值,我会收到两条错误消息:

使用“0”参数调用“ExecuteQuery”时出现异常:“列表” 具有URL的网站上不存在“VMList” ''

枚举集合时出错:集合 集合尚未初始化。尚未请求该集合,或者 请求尚未执行。可能需要显式执行 请求

在谷歌搜索了很多东西后,我尝试了改变很多东西,但似乎没有任何效果。我想我的问题是:为什么在SharePoint上找不到该列表?初始化一个集合意味着什么,或者这只是一个授权问题