Guest User

Untitled

a guest
Aug 23rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. $Url = "http://sharepoint2010/myweb/Shared%20Documents/aaa.txt"
  2. $Path = "C:testaaa.txt"
  3. $Username = ""
  4. $Password = ""
  5.  
  6. $WebClient = New-Object System.Net.WebClient
  7. $WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
  8. $WebClient.DownloadFile( $url, $path )
  9.  
  10. Add-PSSnapin Microsoft.SharePoint.PowerShell
  11.  
  12. $destination = "C:\test\"
  13. $web = Get-SPWeb -Identity "http://sharepoint2010/myweb/"
  14. $list = $web.GetList("http://sharepoint2010/myweb/Shared%20Documents/")
  15.  
  16. function ProcessFolder {
  17. param($folderUrl)
  18. $folder = $web.GetFolder($folderUrl)
  19. foreach ($file in $folder.Files) {
  20. #Ensure destination directory
  21. $destinationfolder = $destination + "/" + $folder.Url
  22. if (!(Test-Path -path $destinationfolder))
  23. {
  24. $dest = New-Item $destinationfolder -type directory
  25. }
  26. #Download file
  27. $binary = $file.OpenBinary()
  28. $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
  29. $writer = New-Object System.IO.BinaryWriter($stream)
  30. $writer.write($binary)
  31. $writer.Close()
  32. #Delete file by deleting parent SPListItem
  33. $list.Items.DeleteItemById($file.Item.Id)
  34. }
  35. }
  36.  
  37. #Download root files
  38. ProcessFolder($list.RootFolder.Url)
  39. #Download files in folders
  40. foreach ($folder in $list.Folders) {
  41. ProcessFolder($folder.Url)
  42. }
  43.  
  44. #Delete folders
  45. foreach ($folder in $list.Folders) {
  46. try {
  47. $list.Folders.DeleteItemById($folder.ID)
  48. }
  49. catch {
  50. #Deletion of parent folder already deleted this folder
  51. #I really hate this
  52. }
  53. }
Add Comment
Please, Sign In to add comment