简体   繁体   English

将[Microsoft.SharePoint.Client.ClientContext]强制转换为Powershell类方法会导致错误

[英]Casting [Microsoft.SharePoint.Client.ClientContext] to a Powershell Class Method results in an error

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: 我在脚本顶部添加了require dll:

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? 对出什么问题有任何想法吗?

I figured this out: you can't import dlls in a script that uses classes. 我发现了这一点:您无法在使用类的脚本中导入dll。 the workaround is to import the binaries in another script and load the classes in by dot sourcing the script containing the classes. 解决方法是将二进制文件导入另一个脚本并通过点源包含类的脚本来加载类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Powershell 将文件上传到 Sharepoint Online (Microsoft 365)(选项 4 - 使用 Microsoft.SharePoint.Client.ClientContext) - Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 4 - Using Microsoft.SharePoint.Client.ClientContext) 使用Powershell连接到sharepoint oniline:找不到类型为Microsoft.SharePoint.Client.ClientContext的适当构造函数 - connecting to sharepoint oniline using Powershell : Cannot find an appropriate constructor for type Microsoft.SharePoint.Client.ClientContext 使用csom clientcontext castto方法的powershell - powershell with csom clientcontext castto method 为Microsoft SharePoint添加PowerShell管理单元时出错 - Error when adding powerShell snapins for Microsoft SharePoint 在Powershell 2.0中使用SharePoint Online客户端组件(Microsoft.SharePoint.Client) - Using SharePoint Online Client components (Microsoft.SharePoint.Client) with powershell 2.0 无法在Powershell脚本中加载Microsoft.SharePoint.Client.dll - Cannot load Microsoft.SharePoint.Client.dll in powershell script Powershell错误Add-PSSnapin“ Microsoft.SharePoint.PowerShell” - Powershell error Add-PSSnapin “Microsoft.SharePoint.PowerShell” 在Powershell中将int转换为chars会产生意外结果 - Casting int to chars in Powershell has unexpected results 使用Powershell连接到Microsoft Access DB / SharePoint列表 - Connect to Microsoft Access DB/SharePoint List with Powershell Apply-PnPProvisioningTemplate:找不到方法'System.String Microsoft.SharePoint.Client.WebParts.WebPartDefinition.get_ZoneId()' - Apply-PnPProvisioningTemplate : Method not found 'System.String Microsoft.SharePoint.Client.WebParts.WebPartDefinition.get_ZoneId()'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM