2011-04-30 8 views
7

現在、ASP.NET MVC Webサイトから一部のExchange 2010操作を自動化するアプリケーションを構築しています。PowerShell ParameterBindingException

今、私はNew-AddressListコマンドを呼び出そうとするとParameterBindingExceptionを実行しました。

私は次の呼び出し(作品)を作成しようとしています

new-AddressList -Name "7 AL" -RecipientContainer "myDomain.local/Customers/7" -IncludedRecipients 'AllRecipients' -Container '\' -DisplayName "7 AL" 

を私は次でそれをやっている:

var NewAddressList = new Command("New-AddressList"); 
NewAddressList.Parameters.Add("Name", "7 AL"); 
NewAddressList.Parameters.Add("RecipientContainer", "myDomain.local/Customers/7"); 
NewAddressList.Parameters.Add("IncludedRecipients", "AllRecipients"); 
NewAddressList.Parameters.Add("Container", @"\"); 
NewAddressList.Parameters.Add("DisplayName", "7 AL"); 
CommandsList.Add(NewAddressList); 

このcommandlistは私が呼び出しパイプラインに提供され、

New-AddressList:入力オブジェクトは、コマンドがパイプライン入力を受け取っていないか、または入力とそのプロパティがパイプライン入力を受け取るパラメータと一致しません。

  • CategoryInfo:InvalidArgument:(7:PSObject)[新-AddressListを]、ParameterBindingException
  • FullyQualifiedErrorId:InputObjectNotBound、Microsoft.Exchange.Management.SystemConfigurationTasks.NewAddressList

引き起こす可能性があるものにどれ手がかりこの?トレース・コマンドによる

出力が得られます。

PS C:\Users\ext_kefu> Trace-Command -Name parameterbinding -Expression {New-AddressList -Name "7 AL" -RecipientContainer "myDomain.local/Customers/7" -IncludedRecipients 'AllRecipients' -Container '\' -DisplayName "7 AL"} -PSHost 
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [New-AddressList] 
DEBUG: ParameterBinding Information: 0 :  BIND arg [7 AL] to parameter [Name] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [System.String] 
DEBUG: ParameterBinding Information: 0 :    Parameter and arg types the same, no coercion is needed. 
DEBUG: ParameterBinding Information: 0 :   BIND arg [7 AL] to param [Name] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 :  BIND arg [myDomain.local/Customers/7] to parameter [RecipientContainer] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [Microsoft.Exchange.Configuration.Tasks.OrganizationalUnitIdParameter] 
DEBUG: ParameterBinding Information: 0 :    Trying to convert argument value from System.String to Microsoft.Exchange.Configuration.Tasks.OrganizationalUnitIdParameter 
DEBUG: ParameterBinding Information: 0 :    CONVERT arg type to param type using LanguagePrimitives.ConvertTo 
DEBUG: ParameterBinding Information: 0 :    CONVERT SUCCESSFUL using LanguagePrimitives.ConvertTo: [myDomain.local/Customers/7] 
DEBUG: ParameterBinding Information: 0 :   BIND arg [myDomain.local/Customers/7] to param [RecipientContainer] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 :  BIND arg [AllRecipients] to parameter [IncludedRecipients] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [System.Nullable[Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType]] 
DEBUG: ParameterBinding Information: 0 :    Trying to convert argument value from System.String to System.Nullable[Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType] 
DEBUG: ParameterBinding Information: 0 :    CONVERT arg type to param type using LanguagePrimitives.ConvertTo 
DEBUG: ParameterBinding Information: 0 :    CONVERT SUCCESSFUL using LanguagePrimitives.ConvertTo: [AllRecipients] 
DEBUG: ParameterBinding Information: 0 :   BIND arg [AllRecipients] to param [IncludedRecipients] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 :  BIND arg [\] to parameter [Container] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [Microsoft.Exchange.Configuration.Tasks.AddressListIdParameter] 
DEBUG: ParameterBinding Information: 0 :    Trying to convert argument value from System.String to Microsoft.Exchange.Configuration.Tasks.AddressListIdParameter 
DEBUG: ParameterBinding Information: 0 :    CONVERT arg type to param type using LanguagePrimitives.ConvertTo 
DEBUG: ParameterBinding Information: 0 :    CONVERT SUCCESSFUL using LanguagePrimitives.ConvertTo: [\] 
DEBUG: ParameterBinding Information: 0 :   BIND arg [\] to param [Container] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 :  BIND arg [7 AL] to parameter [DisplayName] 
DEBUG: ParameterBinding Information: 0 :   COERCE arg to [System.String] 
DEBUG: ParameterBinding Information: 0 :    Parameter and arg types the same, no coercion is needed. 
DEBUG: ParameterBinding Information: 0 :   BIND arg [7 AL] to param [DisplayName] SUCCESSFUL 
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [New-AddressList] 
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [New-AddressList] 
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing 
DEBUG: ParameterBinding Information: 0 : CALLING EndProcessing 

Name      DisplayName    RecipientFilter 
----      -----------    --------------- 
7 AL      7 AL      Alias -ne $null 

答えて

2

私は、彼らが関連していないので、各コマンドは、個別に呼び出されなければならないことがわかりました。質問はPowershellパイプラインの概念の誤解から生じました。

1

なぜあなたはvarとしてコマンドを宣言していますか?私は意味:その後

 
Command NewAddressList = new Command("New-AddressList"); 

CommandParameterオブジェクト(提案hereなど)などのコマンドを追加してみてください:

最後に
 
CommandParameter NameParam = new CommandParameter("Name","7 AL"); 
NewAddressList.Parameters.Add(NameParam); 

、なぜあなたは直接Powershellクラスを使用していませんか?


EDIT:さらに推測

をトレースした後、使用しているParameters.Addのオーバーロードされたバージョンは、引数としてキー(文字列)と値(オブジェクト)をとります。おそらくC#はpowershellと同じ良い仕事をしません:/。必要な型のオブジェクトとして値を渡してみてください。たとえば、included-recipientパラメータにはMicrosoft.Exchange.Data.Directory.Recipient.WellKnownRecipientTypeが必要です。

キャストを試してください。

例:

 
Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType allrecips = (Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType) "AllRecipients"; 
NewAddressList.Parameters.Add("IncludedRecipients", allrecips); 

か(私はそれが愚かかもしれ知っている):

 
NewAddressList.Parameters.Add("IncludedRecipients", "[Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType] AllRecipients"); 
+0

ありがとうございました。残念ながら、それは何も変わらなかった。 var-thingは単なる習慣です。 私はPowershellクラスのラッパーを持っているので、私はラッパーに渡すコレクションを作成しています。 – kfuglsang

+0

コマンドがpowershellのどちらかで動作していますか? 'Trace-Command'を使ってトレースを取得できますか? –

+0

元の質問をトレース出力で更新しました。コマンドは正常に動作します。 – kfuglsang

関連する問題