2011-04-30 7 views
7

Actualmente estoy compilando una aplicación para automatizar algunas operaciones de Exchange 2010 desde un sitio web ASP.NET MVC.PowerShell ParameterBindingException

En este momento, me he encontrado con una ParameterBindingException cuando intento invocar el comando New-AddressList.

estoy tratando de crear la siguiente llamada (que trabaja):

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

lo estoy haciendo por lo siguiente:

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

Este CommandList se proporciona a una tubería que invoco, dándome el siguiente error:

New-AddressList: El objeto de entrada no puede vincularse a ningún parámetro para el comando ya sea porque el comando no toma la entrada de la tubería o el la entrada y sus propiedades no coinciden con ninguno de los parámetros que toman entrada de canalización.

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

Cualquier pistas sobre lo que podría causar ¿esta?

salida con Trace-Command da:

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 

Respuesta

2

me encontré con que cada comando debe ser invocado por separado, ya que no están relacionados. La pregunta surgió de mi malentendido del concepto de oleoductos Powershell.

1

¿Por qué estás declarando comando como var? Es decir:

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

Luego, trate de añadir comandos como CommandParameter objetos (como se sugiere here):

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

Por último, ¿por qué no usar la clase Powershell directamente?


EDIT: Además conjetura después de trazar

La versión sobrecargada de Parameters.Add está utilizando toma como argumentos una clave (cadena) y un valor (objeto). Probablemente C# no haga el mismo buen trabajo que powershell hace: /. Intente pasar valores como objetos del tipo requerido. Por ejemplo, el parámetro included-recipient quiere un Microsoft.Exchange.Data.Directory.Recipient.WellKnownRecipientType.

Try castts.

Ejemplo:

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

o (Sé que puede ser tonta):

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

Gracias por su respuesta.Lamentablemente, no cambió nada. Lo var-thing es solo un hábito. Tengo un contenedor para la clase Powershell y, por lo tanto, estoy creando una Colección que paso a mi contenedor. – kfuglsang

+0

¿Estás seguro de que el comando funciona desde PowerShell? ¿Eres capaz de obtener una traza usando 'Trace-Command'? –

+0

He actualizado la pregunta original con la salida de rastreo. El comando funciona correctamente. – kfuglsang