sharepoint - 在 PowerShell 中,尽管我调用 LoadWithPartialName,但对象未加载

标签 sharepoint powershell wss-3.0

我有一个 .ps1 文件,可以从 PS 提示符执行。在文件的顶部我有:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

在后面的代码中,它有:

$site = new-object Microsoft.SharePoint.SPSite $url;

我收到以下错误:

Unable to find type [Microsoft.SharePoint.SPWeb]: make sure that the assembly containing this type is loaded.

如果我直接在提示符下运行 LoadWithPartialName 语句,那么我就可以执行该脚本。

我做错了什么?

--更新--

当我删除空白时,制作代码:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

错误没有改变,因为 LoadWithPartialName 执行时没有错误。

--新信息--

这与添加带有 SPWeb 类型参数的函数有关。

这有效:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$url = "http://siteurl/"
$site = new-object Microsoft.SharePoint.SPSite $url;
$site.Dispose();

这有效:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function doSomething(){ }
$url = "http://siteurl/"
$site = new-object Microsoft.SharePoint.SPSite $url;
$site.Dispose();

但是如果(您必须在出现问题之前启动一个新的 PS session 。此外,该函数是在 SPSite 第一次实例化之前还是之后并不重要:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function doSomething(    [Microsoft.SharePoint.SPWeb] $web  ){ }
$url = "http://siteurl/"
$site = new-object Microsoft.SharePoint.SPSite $url;
$site.Dispose();

我认为第二个解决方法是不键入参数或将负载放入另一个 ps1 中。

最佳答案

该大会是否有可能不在 GAC 中?如果没有,则需要在 PowerShell 安装目录中才能找到 LoadWithPartialName。仅供引用,LoadWithPartialName 方法已过时,不推荐。如果您使用的是 PowerShell V2,请尝试在文件系统上找到 SharePoint.dll 并使用 Add-Type 例如:

Add-Type -Path <path>\Microsoft.SharePoint.dll

关于sharepoint - 在 PowerShell 中,尽管我调用 LoadWithPartialName,但对象未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9929452/

相关文章:

powershell - 如何使用 powershell 删除 RavenDB?

powershell - 尝试通过 PowerShell 脚本查找并终止进程

SharePoint 内容类型 : deleting columns from the parent

sharepoint - "NewWeb"和 "Blank"配置在 WSS 站点定义中有什么意义

javascript - Sharepoint Teamsite-calendar-webpart - 将约会保存到 Outlook

sharepoint - 如何在 WSP 中包含配置文件?

javascript - SharePoint - Angular 2+ 中的 GetURLKeyValue

powershell - boolean和bool的区别?

php - PHP Intranet 可以共享 Windows 登录名吗?

sharepoint - SharePoint 功能部署中的时间安排