我有一个脚本,它使用指定的文本从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.
我认为登录不正确的问题。我尝试了不同的品种。没有运气。
答案 0 :(得分:1)
以下是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"