I am trying to connect to SharePoint 2013 site with CSOM using a function with 2 arguments. When i am giving only $x that is site URL as argument then code is working fine but when i am giving two arguments to function then it is not working.

Error is

New-Object : Cannot find an overload for "ClientContext" and the argument count: "2". At line:3 char:9 + $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($z) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand .

Please help as i am new to SharePoint Powershell.


    function a($x,$y){
     $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($x)
        $ctx.Credentials = New-Object System.Net.NetworkCredential($loginname,$pwd) 
    $pwd = Read-Host "Enter Password of SharePoint 2013 site owner "-AsSecureString
    $loginname = "username"
    $x = "https://cortona.sharepoint2013.com/sites/abc"
    $y = 2
  • 1
    Call the function as a $x $y – Deepmala Apr 30 '19 at 19:49
  • @deepmala it worked !! Thanks. Do you have any idea why PowerShell behaves like that for arguments? – Adarsh Awasthi Apr 30 '19 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.