Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Url = "http://sharepoint2010/myweb/Shared%20Documents/aaa.txt"
- $Path = "C:testaaa.txt"
- $Username = ""
- $Password = ""
- $WebClient = New-Object System.Net.WebClient
- $WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
- $WebClient.DownloadFile( $url, $path )
- Add-PSSnapin Microsoft.SharePoint.PowerShell
- $destination = "C:\test\"
- $web = Get-SPWeb -Identity "http://sharepoint2010/myweb/"
- $list = $web.GetList("http://sharepoint2010/myweb/Shared%20Documents/")
- 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()
- #Delete file by deleting parent SPListItem
- $list.Items.DeleteItemById($file.Item.Id)
- }
- }
- #Download root files
- ProcessFolder($list.RootFolder.Url)
- #Download files in folders
- foreach ($folder in $list.Folders) {
- ProcessFolder($folder.Url)
- }
- #Delete folders
- foreach ($folder in $list.Folders) {
- try {
- $list.Folders.DeleteItemById($folder.ID)
- }
- catch {
- #Deletion of parent folder already deleted this folder
- #I really hate this
- }
- }
Add Comment
Please, Sign In to add comment