How to uploads files to OneDrive for Business using Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-136332%22%20slang%3D%22en-US%22%3EHow%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136332%22%20slang%3D%22en-US%22%3E%3CP%3EI%20tried%20the%20sample%20powershell%20code%20in%20below%20link%2C%20getting%20error%20as%20path%20not%20found.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.spiceworks.com%2Ftopic%2F2001221-powershell-script-to-upload-file-to-onedrive-business%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcommunity.spiceworks.com%2Ftopic%2F2001221-powershell-script-to-upload-file-to-onedrive-business%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESame%20error%20with%20any%20onedrive%20folder.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20anyone%20share%20any%20sample%20and%20the%20settings%20I%20need%20to%20do%20in%20my%20OneDrive%20account%20for%20scripting.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-136332%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOneDrive%20for%20Business%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%20Commands%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137861%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137861%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20you%20need%20to%20pass%20the%20%24ctx%2C%20%24ctx%20is%20Client%20context%3C%2FP%3E%0A%3CP%3E%24ctx%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%3CBR%20%2F%3E%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24User%2C%24Password)%3CBR%20%2F%3E%24ctx.Credentials%20%3D%20%24Creds%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137859%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137859%22%20slang%3D%22en-US%22%3E%3CP%3EUploadFileInSlice%20(%24ctx%2C%20%24libraryName%2C%20%24fileName%2C%20%24fileChunkSizeInMB)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20is%20the%20%24ctx%20we%20need%20to%20pass%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137847%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137847%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20this%20script%20only%20support%26nbsp%3Bupto%20250%20mb%20size%20for%20single%20file%20so%20if%20you%20want%20to%20upload%20more%20than%20250mb%20file%20size%20of%20single%20file%2C%20you%20can%20refer%20the%20below%20link.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgist.github.com%2Fasadrefai%2Fecfb32db81acaa80282d%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgist.github.com%2Fasadrefai%2Fecfb32db81acaa80282d%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137687%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137687%22%20slang%3D%22en-US%22%3E%3CP%3EAnd%20also%20I%20am%20getting%20below%20error%20if%20I%20am%20uploading%20files%20larger%20than%20200%20MB.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EException%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20operation%20has%20timed%20out%22%3CBR%20%2F%3EAt%20C%3A%5CUsers%5Cuday-%5CDesktop%5CNew%20Text%20Document%20(2).ps1%3A55%20char%3A1%3CBR%20%2F%3E%2B%20%24Context.ExecuteQuery()%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5B%5D%2C%20MethodInvocationException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20WebException%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137683%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137683%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%2C%3CBR%20%2F%3EI%20will%20try%20this%20script.%3CBR%20%2F%3EAnd%20also%20if%20we%20share%20a%20folder%20internally%20with%20other%20team%20members%2C%20or%20if%20I%20open%20a%20shared%20folder%20by%20someone%20else%2C%20How%20to%20upload%20to%20that%20folder%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-137679%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-137679%22%20slang%3D%22en-US%22%3E%3CP%3Eyou%20can%20try%20this%20modified%20script%20and%20this%20script%20support%20sub%20folder%20in%20document%20library%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%24User%20%3D%20%22testuser%40domainname.com%22%20%0A%24SiteURL%20%3D%20%22https%3A%2F%2Ftest-my.sharepoint.com%2Fpersonal%2Ftestuser_domainame_com%22%3B%0A%0A%0A%24Folder%20%3D%20%22C%3A%5CUsers%5CDesktop%5CNew%20folder%22%0A%23DocDocLibName%20is%20document%20libary%20name%20%0A%24DocLibName%20%3D%20%22Documents%22%0A%24foldername%20%3D%20%22Attachments%22%0A%0A%23Add%20references%20to%20SharePoint%20client%20assemblies%20and%20authenticate%20to%20Office%20365%20site%20%E2%80%93%20required%20for%20CSOM%0AAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.dll%22%0AAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.Runtime.dll%22%0A%0A%0A%24Password%20%20%3D%20ConvertTo-SecureString%20%E2%80%98test1234%E2%80%99%20-AsPlainText%20-Force%0A%0A%0A%23Bind%20to%20site%20collection%0A%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%0A%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24User%2C%24Password)%0A%0A%0A%24Context.Credentials%20%3D%20%24Creds%0A%0A%23Retrieve%20list%0A%24List%20%3D%20%24Context.Web.Lists.GetByTitle(%22%24DocLibName%22)%0A%24Context.Load(%24List)%0A%24Context.Load(%24List.RootFolder)%0A%24Context.ExecuteQuery()%0A%24ServerRelativeUrlOfRootFolder%20%3D%20%24List.RootFolder.ServerRelativeUrl%0A%24uploadFolderUrl%3D%20%20%24ServerRelativeUrlOfRootFolder%2B%22%2F%22%2B%24foldername%0A%0A%0A%0A%0A%23Upload%20file%0AForeach%20(%24File%20in%20(dir%20%24Folder%20-File))%0A%7B%0A%24FileStream%20%3D%20New-Object%20IO.FileStream(%24File.FullName%2C%5BSystem.IO.FileMode%5D%3A%3AOpen)%0A%24FileCreationInfo%20%3D%20New-Object%20Microsoft.SharePoint.Client.FileCreationInformation%0A%24FileCreationInfo.Overwrite%20%3D%20%24true%0A%24FileCreationInfo.ContentStream%20%3D%20%24FileStream%0A%24FileCreationInfo.URL%20%3D%20%24File%0A%20if(%24foldername%20-eq%20%24null)%0A%20%20%7B%0A%20%20%24Upload%20%3D%20%24List.RootFolder.Files.Add(%24FileCreationInfo)%0A%20%20%7D%0A%20%20Else%0A%20%20%7B%0A%20%20%20%24targetFolder%20%3D%20%24Context.Web.GetFolderByServerRelativeUrl(%24uploadFolderUrl)%0A%20%20%20%24Upload%20%3D%20%24targetFolder.Files.Add(%24FileCreationInfo)%3B%0A%20%20%7D%0A%23%24Upload%20%3D%20%24List.RootFolder.Files.Add(%24FileCreationInfo)%0A%24Context.Load(%24Upload)%0A%24Context.ExecuteQuery()%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136516%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136516%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20is%20not%20working%20for%20sub%20folders.%3C%2FP%3E%0A%3CP%3E%24DocLibName%20%3D%20%22Documents%22%20it%20is%20working(only%20for%20files%2C%20not%20folders)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24DocLibName%20%3D%20%22Attachments%22%20or%20%24DocLibName%20%3D%20%22Documents%2FAttachments%22%20it%20is%20not%20working.%3C%2FP%3E%0A%3CP%3EAttachments%20is%20the%20name%20of%20subfolder%20we%20created.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-136490%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-136490%22%20slang%3D%22en-US%22%3EHave%20you%20identified%20in%20which%20line%20are%20you%20having%20the%20error%3F%20The%20script%20is%20quite%20straightforward%20and%20it%20should%20work%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-572736%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-572736%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3058%22%20target%3D%22_blank%22%3E%40Manidurai%20Mohanamariappan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%20I%20tried%20this%20script%20but%20getting%20below%20error%3A%3C%2FP%3E%3CP%3EException%20calling%20%E2%80%9CExecuteQuery%E2%80%9D%20with%20%E2%80%9C0%E2%80%9D%20argument(s)%3A%20%E2%80%9CThe%20sign-in%20name%20or%20password%20does%20not%20match%20one%20in%20the%20Microsoft%20account%20system.%E2%80%9D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20the%20account%20do%20exists.%3C%2FP%3E%3CP%3EThe%20account%20is%20working%20if%20I%20login%20through%20webportal.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-666364%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-666364%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%20I%20get%20the%20same%20error.%3C%2FP%3E%3CP%3EThis%20worked%20'previously'%20(%20until%20about%20February%20this%20year%26nbsp%3B).%3C%2FP%3E%3CP%3EI%20am%20having%20the%20same%20issue%20with%20uploading%20to%20sharepoint%20teams%20sites.%3C%2FP%3E%3CP%3EI%20have%20tried%20every%20piece%20of%20code%20and%20uploader%20I%20could%20find%20in%20the%20last%202%20weeks%20and%20nothing%20is%20working.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867042%22%20slang%3D%22es-ES%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867042%22%20slang%3D%22es-ES%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F3058%22%20target%3D%22_blank%22%3E%40Manidurai%20Mohanamariappan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%20for%20your%20code...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebut%2C%20how%20can%20i%20do%20the%20same%20uploading%20to%20folders%20instead%20of%20lists%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eregards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1072922%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20uploads%20files%20to%20OneDrive%20for%20Business%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1072922%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F354117%22%20target%3D%22_blank%22%3E%40Gerhard_Wessels%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20had%20to%20modify%20this%20line%20to%20make%20it%20work%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24FileCreationInfo.URL%20%3D%20%24File%3CBR%20%2F%3E%3CBR%20%2F%3Eto%20this%3CBR%20%2F%3E%3CBR%20%2F%3E%24FileCreationInfo.URL%20%3D%20%24ServerRelativeUrlOfRootFolder%20%2B%20%22%2F%22%20%2B%20%24File.Name%3C%2FPRE%3E%3CP%3EThis%20needs%20to%20be%20a%20web%20relative%20url%20and%20not%20the%20file%20path.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIts%20should%20equate%20to%20something%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2Fpersonal%2Fyour_name_domain_com%2FDocuments%2FFilename.txt%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

I tried the sample powershell code in below link, getting error as path not found.

https://community.spiceworks.com/topic/2001221-powershell-script-to-upload-file-to-onedrive-business

 

 

Same error with any onedrive folder.

 

Can anyone share any sample and the settings I need to do in my OneDrive account for scripting.

12 Replies
Highlighted
Have you identified in which line are you having the error? The script is quite straightforward and it should work
Highlighted

It is not working for sub folders.

$DocLibName = "Documents" it is working(only for files, not folders)

 

$DocLibName = "Attachments" or $DocLibName = "Documents/Attachments" it is not working.

Attachments is the name of subfolder we created.

 

 

Highlighted

you can try this modified script and this script support sub folder in document library

 

 

$User = "testuser@domainname.com" 
$SiteURL = "https://test-my.sharepoint.com/personal/testuser_domainame_com";


$Folder = "C:\Users\Desktop\New folder"
#DocDocLibName is document libary name 
$DocLibName = "Documents"
$foldername = "Attachments"

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"


$Password  = ConvertTo-SecureString ‘test1234’ -AsPlainText -Force


#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)


$Context.Credentials = $Creds

#Retrieve list
$List = $Context.Web.Lists.GetByTitle("$DocLibName")
$Context.Load($List)
$Context.Load($List.RootFolder)
$Context.ExecuteQuery()
$ServerRelativeUrlOfRootFolder = $List.RootFolder.ServerRelativeUrl
$uploadFolderUrl=  $ServerRelativeUrlOfRootFolder+"/"+$foldername




#Upload file
Foreach ($File in (dir $Folder -File))
{
$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
 if($foldername -eq $null)
  {
  $Upload = $List.RootFolder.Files.Add($FileCreationInfo)
  }
  Else
  {
   $targetFolder = $Context.Web.GetFolderByServerRelativeUrl($uploadFolderUrl)
   $Upload = $targetFolder.Files.Add($FileCreationInfo);
  }
#$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()

 

Highlighted

Thank you,
I will try this script.
And also if we share a folder internally with other team members, or if I open a shared folder by someone else, How to upload to that folder?

Highlighted

And also I am getting below error if I am uploading files larger than 200 MB.

 

Exception calling "ExecuteQuery" with "0" argument(s): "The operation has timed out"
At C:\Users\uday-\Desktop\New Text Document (2).ps1:55 char:1
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

Highlighted

Yes, this script only support upto 250 mb size for single file so if you want to upload more than 250mb file size of single file, you can refer the below link.

 

https://gist.github.com/asadrefai/ecfb32db81acaa80282d

 

 

 

Highlighted

UploadFileInSlice ($ctx, $libraryName, $fileName, $fileChunkSizeInMB)

 

What is the $ctx we need to pass?

Highlighted

Yes you need to pass the $ctx, $ctx is Client context

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$ctx.Credentials = $Creds

 

 

 

 

 

Highlighted

@Manidurai Mohanamariappan 

Hi, I tried this script but getting below error:

Exception calling “ExecuteQuery” with “0” argument(s): “The sign-in name or password does not match one in the Microsoft account system.”

 

But the account do exists.

The account is working if I login through webportal.

Highlighted

Hello, I get the same error.

This worked 'previously' ( until about February this year ).

I am having the same issue with uploading to sharepoint teams sites.

I have tried every piece of code and uploader I could find in the last 2 weeks and nothing is working.

Highlighted

@Manidurai Mohanamariappan 

thanks for your code...

 

but, how can i do the same uploading to folders instead of lists?

 

regards

Highlighted

@Gerhard_Wessels 

 

I had to modify this line to make it work

 

$FileCreationInfo.URL = $File

to this

$FileCreationInfo.URL = $ServerRelativeUrlOfRootFolder + "/" + $File.Name

This needs to be a web relative url and not the file path. 

 

Its should equate to something like:

 

/personal/your_name_domain_com/Documents/Filename.txt