Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Foreach ($File in (dir $LocalBckupFolder))
- {
- $StartAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
- Add-Content $log "$StartAFile :: Start Upload file: $File.name"
- $FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
- $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
- $FileCreationInfo.Overwrite = $true
- $FileCreationInfo.ContentStream = $FileStream
- $FileCreationInfo.URL = $File
- $Upload = $SPfolder.Files.Add($FileCreationInfo)
- $ctx.Load($Upload)
- $ctx.ExecuteQuery()
- $FinishAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
- Add-Content $log "$FinishAFile :: Done Upload file: $File.name"
- }
- $ctx.Dispose()
- $username = "admin@domain.onmicrosoft.com"
- $password = "Password"
- $url = "https://domain.sharepoint.com/sites/Test"
- $path = "C:temptest";
- $destination = $url + "/Shared Documents"; #lib partial url
- $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
- # the path here may need to change if you used e.g. C:Lib..
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- # connect/authenticate to SharePoint Online and get ClientContext object..
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- $webclient = New-Object System.Net.WebClient;
- $webclient.Headers["Cookie"] = $credentials.GetAuthenticationCookie($url)
- Get-ChildItem $path | Where-Object {$_.Length -gt 0} | ForEach-Object {
- $webclient.UploadFile($destination + "/" + $_.Name, "PUT", $_.FullName);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement