0

Here is my code:

Class Tracker : WebObject {

$url
$username
$password

[Microsoft.SharePoint.Client.ClientContext] Context() {

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($this.url)
    return $context
}

Tracker ([string]$url,[string]$username,[string]$password) {
    $this.url = $url
    $this.username = $username
    $this.password = $password
}

I have added the require dlls at the top of the script:

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

However, when I run it I receive the following error:

Unable to find type [Microsoft.SharePoint.Client.ClientContext].

Any thoughts on what's going wrong?

1 Answers1

0

I figured this out: you can't import dlls in a script that uses classes. the workaround is to import the binaries in another script and load the classes in by dot sourcing the script containing the classes.