2012-02-23 82 views
0

我正在嘗試編寫一個PowerShell腳本來啓用給定網站集的所有子站點上的功能,並且一切都會順利進行我試圖讓實際功能被啓用。我成功地使用SharePoint API無處不在,但是當我得到這個:PowerShell和SharePoint 2007:無法找到「添加」的重載和參數計數:「2」

$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) 

我不能說,這個異常使多大意義,我,我也可以找到任何東西從這裏或關鍵術語搜索資源的幫助。

有沒有人遇到過這樣的事情?如果是這樣,我該如何糾正它。

+0

假設$ Feature.Id是System.Guid類型,我不確定。該異常意味着您使用的是錯誤的Add方法,但檢查MSDN時,它顯示*有一個Add方法需要一個GUID和一個布爾值:http://msdn.microsoft.com/en-us/library/ ms465255.aspx – 2012-02-24 00:36:55

+0

這就是我感到困惑。 – 2012-02-24 17:05:01

回答

0

我已經寫了一個函數來返回被激活的功能的SPFeatureDefinition,顯然它返回了兩個項目的數組。數組中的第二項是SPFeatureDefinition,我不知道這一點。所以,在調用該功能後,我這樣做:

$Feature = $Feature[1] 

在此之後,一切工作正常。

相關問題