![](/img/trans.png)
[英]How to get a list of all documents from SharePoint using PowerShell?
[英]Inability to authenticate and download the list of Word documents at SharePoint server by using PowerShell
我有一个脚本,该脚本使用指定的文本从SharePoint服务器检索到Word文档的所有链接。 之后将文档列表复制到本地驱动器。
$siteAddress = "http://d/D/O%20S/S/O/S/"
$invokeData = (Invoke-WebRequest -Uri $siteAddress -UseDefaultCredentials).Links.Href| Select-String "/Dev/O/S/OS2017-1/S/"
foreach ($item in $invokeData)
{
$filename = "http://docs" + $item
$ssLDocName = Split-path $item -Leaf
$ssLDocName2 = "D:\FF\" + $ssLocalDocName
$userName = "John Doe"
$passWord = Get-Content D:\Password.txt | ConvertTo-SecureString
$C = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Start-BitsTransfer -Credential $C -Source $filename -Destination $ssLocalDocName
}
当我执行它时,我收到错误消息
Start-BitsTransfer : HTTP status 401: The requested resource requires user authentication.
我认为登录不正确会出现问题。 我尝试了不同的品种。 没运气。
这是通过PowerShell从SharePoint 2013下载文件的示例代码。
希望能帮助到你
Function Download-File([string]$FileUrl,[string]$DownloadPath)
{
$fileName = [System.IO.Path]::GetFileName($FileUrl)
$downloadFilePath = [System.IO.Path]::Combine($DownloadPath,$fileName)
$client = New-Object System.Net.WebClient
$client.Credentials = new-object System.Net.NetworkCredential("lee", "password", "domain")
$client.DownloadFile($FileUrl, $downloadFilePath)
$client.Dispose()
}
Download-File -FileUrl http://sp:12001/MyDoc3/TestLee.pdf -DownloadPath "C:\Lee\PSDownLoad"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.