2011-04-30 2 views
7

현재 ASP.NET MVC 웹 사이트에서 일부 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 내가 호출 파이프 라인에 제공되고, 다음 오류를 내게 :

새 주소 목록 : 입력 개체는 명령에 대한 매개 변수에 바인딩 할 수 없습니다.이 명령은 파이프 라인 입력 또는 입력 및 해당 속성이 파이프 라인 입력을받는 매개 변수와 일치하지 않습니다.

  • 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로 명령을 선포? 내 말은 :

마지막으로
 
CommandParameter NameParam = new CommandParameter("Name","7 AL"); 
NewAddressList.Parameters.Add(NameParam); 

, 왜 당신이 직접 Powershell 클래스를 사용하지 않는 :

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

CommandParameter 객체 (here를 제안)로 명령을 추가하려고?


편집 : 당신이 사용하는

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 클래스의 래퍼가있어서 래퍼에 전달하는 Collection 을 생성하고 있습니다. – kfuglsang

+0

명령이 powershell에서 작동하고 있습니까? 'Trace-Command'를 사용하여 트레이스를 얻을 수 있습니까? –

+0

원본 질문을 추적 출력으로 업데이트했습니다. 명령이 올바르게 작동합니다. – kfuglsang