我正在尝试使用 powershell 从我们的团队站点(sharepoint?)下载单个文件。powershell 的原因是由于我们的策略(映射、在库中打开、webDav 访问...),任何其他方法都失败了
我已经尝试了几个我在这里找到的 PS 脚本,或者在网络上,但仍然没有任何效果......主要是我收到了诸如禁止或无效凭据之类的错误......
我正在使用的最新版本:
function GetSharePointListContext($userName, $password, $isOnline, $siteUrl, $listTitle)
{
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
if($isOnline -eq $true)
{
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securePassword) -Verbose:$false
}
else
{
if($userName -like "*@xyz.com")
{
$context.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::Default
$context.Credentials = New-Object System.Net.NetworkCredential($userName, $securePassword) -Verbose:$false
$context.add_ExecutingWebRequest( ${function:ExecutingWebRequestEventHandler_NoFormsAuth} )
}
else
{
$Context.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::FormsAuthentication
$Context.FormsAuthenticationLoginInfo = New-Object Microsoft.SharePoint.Client.FormsAuthenticationLoginInfo($userName, $securePassword) -Verbose:$false
}
}
$targetList = $Context.Web.Lists.GetByTitle($listTitle) #target list
$Context.Load($targetList)
$Context.ExecuteQuery()
return $targetList;
}
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"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
Add-Type -Path 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.PowerShell.dll'
$userName= ""
$password = ""
$isOnline = $false
$siteUrl = "https://hub.xyzgroup.net/teams/xyzteam/"
$listTitle = "Process Analysts Workplace"
GetSharePointListContext $userName $password $isOnline $siteUrl $listTitle
这将导致:
使用“0”参数调用“ExecuteQuery”的异常:“远程服务器返回错误:(403) Forbidden。” 在 C:\Learning\PowerShell\test8.ps1:28 char:5 + $Context.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
知道有什么问题吗?我意识到这个脚本不是下载文件,而是导致同样的错误:/
谢谢。