首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sharepoint powershell -调用"ExecuteQuery“时出现异常,参数为"0”:“基础连接已关闭:”

sharepoint powershell -调用"ExecuteQuery“时出现异常,参数为"0”:“基础连接已关闭:”
EN

Stack Overflow用户
提问于 2020-04-03 02:30:22
回答 2查看 765关注 0票数 1

有些地方不对劲,我不知道是什么原因,相同的脚本在我的本地机器上工作,但当我在VM中尝试它时,它就不能工作,并抛出异常

-the PowerShell是相同版本的-the相同PowerShell SDK -i添加了允许PowerShell -my用户是管理员-all的规则参数正确,我可以在浏览器中输入SharePoint

代码语言:javascript
复制
Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll'
Clear-Host
# getting all argument before starting the process #
$SiteURL = "user"
$ListName = "list"
$Username ="email"
$Password ="pass"

if ($SiteURL -eq $null -or $ListName -eq $null -or $Username -eq $null -or $Password -eq $null)
    {
        Write-Output "Somthing went wrong!"
        Write-Output "Some of the variables are not correct"
    }
else
    {
        $outfile = $PSCommandPath | Split-Path -Parent
        $outfile += '\items.txt'
        Clear-Host
        Write-Output "Getting Items"
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $securePassword=ConvertTo-SecureString $Password -AsPlainText -Force
        $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $securePassword)
        $Web = $Context.Web
        $List = $Web.get_lists().getByTitle($ListName)
        $itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
        $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
        $Context.Load($ListItems)
        $Context.ExecuteQuery()
        $ListItems | ForEach-Object {
            $output=$_["Title"] + "~~"
            $output | Out-File -FilePath $outfile -Append
        }
        Write-Output "Done!"
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-06 18:22:06

似乎本地计算机的安全性在默认情况下为我的帐户提供了SSL证书,但在虚拟机中缺少该证书,因此我只是使用TLS 1.2调用

代码语言:javascript
复制
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

到我的power-shell代码的第一行,一切都很好。

票数 0
EN

Stack Overflow用户

发布于 2020-04-03 08:59:14

根据我的测试,运行良好。

代码语言:javascript
复制
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" 

Clear-Host
# getting all argument before starting the process #
$SiteURL = "https://xxx.sharepoint.com/sites/lee"
$ListName = "testlist"
$Username ="user@xxx.onmicrosoft.com"
$Password ="password"

if ($SiteURL -eq $null -or $ListName -eq $null -or $Username -eq $null -or $Password -eq $null)
    {
        Write-Output "Somthing went wrong!"
        Write-Output "Some of the variables are not correct"
    }
else
    {
        $outfile = $PSCommandPath | Split-Path -Parent
        $outfile += '\items.txt'
        Clear-Host
        Write-Output "Getting Items"
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $securePassword=ConvertTo-SecureString $Password -AsPlainText -Force
        $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $securePassword)
        $Web = $Context.Web
        $List = $Web.get_lists().getByTitle($ListName)
        $itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
        $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
        $Context.Load($ListItems)
        $Context.ExecuteQuery()
        $ListItems | ForEach-Object {
            $output=$_["Title"] + "~~"
            $output | Out-File -FilePath $outfile -Append
        }
        Write-Output "Done!"
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60998590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档