Asp.net 使用PowerShell进行Sharepoint开发

Asp.net 使用PowerShell进行Sharepoint开发,asp.net,powershell,sharepoint,csom,Asp.net,Powershell,Sharepoint,Csom,我正在尝试使用powershell创建sharepoint Web部件。但每次我加载(Context.Load())某些内容时,都会出现错误 这是我的密码 [Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location)) [Reflection.Assembly]::LoadFile(([System.Reflec

我正在尝试使用powershell创建sharepoint Web部件。但每次我加载(Context.Load())某些内容时,都会出现错误

这是我的密码

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

$tenantAdmin = "#####@ajoncloud.onmicrosoft.com"
$tenantAdminPassword = "#########"
$secureAdminPassword = $(convertto-securestring $tenantAdminPassword -asplaintext -force)
$siteURL = "https://ajoncloud.sharepoint.com/LND"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($tenantAdmin,$secureAdminPassword) 
$ctx.Credentials = $credentials
这部分工作完全正常。但是如果我尝试下面的语句,我会出错

$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
这就是我得到的错误

Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (403) Forbidden."

当我亲自尝试时,您的代码运行良好。也许可以尝试下面的代码片段,并尝试在SharePoint中获取特定的片段。指定特定列表并尝试获取字段值。起初,我在运行代码时出错,但当我尝试其他用户并指定下面的列表时,它开始对两个用户都起作用

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

$tenantAdmin = "your admin account"
$tenantAdminPassword = "your admin password"
$secureAdminPassword = $(ConvertTo-SecureString $tenantAdminPassword -AsPlainText -Force)
$siteURL = "your site/subsite"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
$ctx.credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($tenantAdmin,$secureAdminPassword) 

$listTitle = "The name of your list" 
$list = $ctx.Web.Lists.GetByTitle($listTitle)
$fields = $list.Fields
$qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10000,'ID','Created','Modified','Title')
$items = $list.GetItems($qry)
$ctx.Load($fields)
$ctx.Load($items)
$ctx.ExecuteQuery()

foreach($item in $items){
    $item.FieldValues.Title
}

我尝试了这一点,但在执行ExecuteQuery()语句时再次出现相同的错误。错误:调用带有“0”参数的“ExecuteQuery”时出现异常:“远程服务器返回了一个错误:(403)禁止”。您确定有足够的权限吗?另外,您确定填写了正确的URL吗?有没有可能尝试使用管理员帐户?是的,我有足够的权限。我能够使用C#成功地执行这些语句,但没有使用powershell。您使用的powershell版本是什么?所以我不知道发生了什么,我重新启动了系统,它现在正在工作。