![](/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.