我正在尝试使用powershell从我们的teamsite(sharepoint?)下载单个文件.Towerhell的原因是任何其他方法由于我们的策略而失败(映射,在库中打开,webDav访问...)< / p>
我已经尝试过我在这里或网上找到的几个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)禁止。“在 C:\学习\ PowerShell的\ test8.ps1:28 焦炭:5 + $ Context.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:WebException
知道出了什么问题吗? 我意识到这个脚本不是为了下载文件,而是导致同样的错误:/
感谢。