zoukankan      html  css  js  c++  java
  • PowerShell Download files from a library

    # Check to ensure Microsoft.SharePoint.PowerShell is loaded
    $Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if($Snapin -eq $null){
        Write-host "Loading SharePoint Powershell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"
    }
    $web = Get-SPWeb -Identity http://gdcvmg_sps01
    write-host $web
    $destination = "C:\\test2\\"
    $list = $web.GetList("document lib test2")
    function ProcessFolder {
        param($folderUrl)
        $folder = $web.GetFolder($folderUrl)
        foreach ($file in $folder.Files) {
            #Ensure destination directory
            $destinationfolder = $destination + "/" + $folder.Url 
            if (!(Test-Path -path $destinationfolder))
            {
                $dest = New-Item $destinationfolder -type directory 
            }
            #Download file
            $binary = $file.OpenBinary()
            $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
            $writer = New-Object System.IO.BinaryWriter($stream)
            $writer.write($binary)
            $writer.Close()
        }
    }
    
    #Download root files
    ProcessFolder($list.RootFolder.Url)
    #Download files in folders
    foreach ($folder in $list.Folders) {
        ProcessFolder($folder.Url)
    }
    

      

  • 相关阅读:
    【脑图】iOS的Crash分类和捕获
    Ruby03
    Ruby02
    Ruby01
    如何快速把一个十进制数转换为二进制?
    iOS
    互联网协议基本知识
    XCBB
    iOS
    iOS
  • 原文地址:https://www.cnblogs.com/ilawrence/p/2889301.html
Copyright © 2011-2022 走看看