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.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
function a($x,$y){
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($x)
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname,$pwd)
$web=$ctx.web
$ctx.load($web)
$ctx.ExecuteQuery()
$web.Url
}
$pwd = Read-Host "Enter Password of SharePoint 2013 site owner "-AsSecureString
$loginname = "username"
$x = "https://cortona.sharepoint2013.com/sites/abc"
$y = 2
a($x,$y)