Powershell-download files from a library

Source: Internet
Author: User
# 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_sps01write-host $ web $ Destination =" C: \ Test2 \ "$ list = $ web. getlist ("document lib Test2") functi On processfolder {param ($ folderurl) $ folder = $ web. getfolder ($ folderurl) foreach ($ file in $ folder. files) {# ensure destination directory $ destinationfolder = $ destination + "/" + $ folder. URL if (! (Test-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 filesprocessfolder ($ list. rootfolder. URL) # download files in foldersforeach ($ folder in $ list. folders) {processfolder ($ folder. URL )}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.