PowerShell和SharePoint 2007:找不到“的重载”;加上「;并且参数计数为:“quot;2“;

PowerShell和SharePoint 2007:找不到“的重载”;加上「;并且参数计数为:“quot;2“;,sharepoint,powershell,Sharepoint,Powershell,我正在尝试编写一个PowerShell脚本,以便在给定网站集的所有子网站上启用功能,在我尝试启用实际功能之前,一切都进展顺利。我在任何地方都成功地使用了SharePoint API,但当我做到这一点时: $activatedFeature = $web.Features.Add($Feature.Id, $true) 我得到了一个可笑的例外,我似乎无法理解 System.Management.Automation.MethodException: Cannot find an overload

我正在尝试编写一个PowerShell脚本,以便在给定网站集的所有子网站上启用功能,在我尝试启用实际功能之前,一切都进展顺利。我在任何地方都成功地使用了SharePoint API,但当我做到这一点时:

$activatedFeature = $web.Features.Add($Feature.Id, $true)
我得到了一个可笑的例外,我似乎无法理解

System.Management.Automation.MethodException: Cannot find an overload for "Add" and the argument count: "2".
at System.Management.Automation.Adapter.FindBestMethod(String methodName, MethodInformation[] methods, Object[] arguments, Boolean& expandParamsOnBest)
at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation[] methodInformation, Object[] arguments)
at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments)
at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramArray, Boolean callStatic, Object valueToSet)
at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value)
at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
at System.Management.Automation.AssignmentStatementNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
我不能说这个例外对我有多大意义,也不能从这里的资源或搜索关键术语中找到任何有用的东西


以前有人经历过类似的事情吗?如果是这样,我该如何更正它。

我编写了一个函数来返回被激活功能的SPFeatureDefinition,显然它返回了一个包含两个项目的数组。数组中的第二项是SPFeatureDefinition,我不知道这一点。因此,调用该函数后,我做了以下操作:

$Feature = $Feature[1]

在此之后,一切正常。

假设$Feature.Id是System.Guid类型,我不确定。该异常意味着您使用的Add方法错误,但检查MSDN时,似乎有一个Add方法使用GUID和布尔值:这就是我所困惑的。