Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. Foreach ($File in (dir $LocalBckupFolder))
  2. {
  3. $StartAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
  4. Add-Content $log "$StartAFile :: Start Upload file: $File.name"
  5. $FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
  6. $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
  7. $FileCreationInfo.Overwrite = $true
  8. $FileCreationInfo.ContentStream = $FileStream
  9. $FileCreationInfo.URL = $File
  10. $Upload = $SPfolder.Files.Add($FileCreationInfo)
  11. $ctx.Load($Upload)
  12. $ctx.ExecuteQuery()
  13. $FinishAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
  14. Add-Content $log "$FinishAFile :: Done Upload file: $File.name"
  15. }
  16.  
  17. $ctx.Dispose()
  18.  
  19. $username = "admin@domain.onmicrosoft.com"
  20. $password = "Password"
  21. $url = "https://domain.sharepoint.com/sites/Test"
  22. $path = "C:temptest";
  23. $destination = $url + "/Shared Documents"; #lib partial url
  24.  
  25. $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
  26.  
  27. # the path here may need to change if you used e.g. C:Lib..
  28. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
  29. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  30.  
  31. # connect/authenticate to SharePoint Online and get ClientContext object..
  32. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  33.  
  34. $webclient = New-Object System.Net.WebClient;
  35. $webclient.Headers["Cookie"] = $credentials.GetAuthenticationCookie($url)
  36.  
  37. Get-ChildItem $path | Where-Object {$_.Length -gt 0} | ForEach-Object {
  38. $webclient.UploadFile($destination + "/" + $_.Name, "PUT", $_.FullName);
  39. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement