I want a script that authenticates and then create a folder.

I am not performing the upload from my local machine. It is happening from a continuous integration server so it needs to authenticate.

I see this question about PowerShell folder creation but how to authenticate? automatically create subfolder and save the file in sharepoint using powershell

  • your environment? On-Prem or SPO? Jun 27, 2017 at 14:38
  • This is for On-prem but I see the answer below for both Jun 27, 2017 at 14:48
  • yes, i having scripts for both so just added them. Though it will helpful for others as well. Jun 27, 2017 at 14:49

1 Answer 1



$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $pwd)

For SP-OnPrem

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)

Make Sure you refer to the Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll before using above code.

Also passing the user name and password in plain file is not recommended but i had this sample as of now so posted. You can utilize powershell Get-Credential function to get the credentials at runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.