代码之家  ›  专栏  ›  技术社区  ›  Mikhail R

无法使用PowerShell在SharePoint server上验证和下载Word文档列表

  •  0
  • Mikhail R  · 技术社区  · 7 年前

    我有一个脚本,可以从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.
    

    我认为这是一个错误登录的问题。我尝试了不同的品种。没有运气。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Lee    7 年前

    下面是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"
    
    推荐文章