Get-Mailbox fails with InputObject argument transformation error in Exchange Online
Issue
When Activate calls Exchange Online using remote PowerShell, a mailbox lookup may fail even though the mailbox exists.
The error can look similar to this:
Cannot process argument transformation on parameter 'InputObject'.
Cannot convert the "@{...}" value of type
"Selected.System.Management.Automation.PSCustomObject" to type "Object".
In the observed case, the failing command shown in the exception was:
The stack trace showed the error being raised during a user creation workflow, while attempting to retrieve mailbox details from Exchange Online. The returned object contained a very large mailbox payload with many properties, including OData-style metadata fields and collection properties.
Cause
The issue was caused by the size and shape of the object returned by classic Exchange Online Get-Mailbox.
Get-Mailbox returned a large, deserialised mailbox object. During PowerShell object transformation, the Exchange Online/PowerShell layer attempted to process the object as an InputObject, but failed when converting the selected/deserialised PSCustomObject.
This was not caused by an invalid UPN or a missing mailbox. In the captured failure, Exchange had already resolved the mailbox and returned mailbox details, including properties such as PrimarySmtpAddress, RecipientTypeDetails, Identity, and ExchangeGuid.
Affected pattern
The issue can occur with code that calls:
Activate’s RemotePowerShell.Exec(string command, params object[] args) creates a PowerShell Command and adds the supplied arguments as name/value parameter pairs. The command is then added to a pipeline and invoked.
So the C# call itself is valid. The failure occurs when the Exchange Online command returns or transforms the full mailbox object.
Resolution
Use Get-EXOMailbox and request only the required property.
For example, when only the Exchange GUID is required:
foreach (PSObject o in eol.Exec(
"Get-EXOMailbox",
"Identity", upn,
"Properties", new[] { "ExchangeGuid" }))
{
var prop = o.Properties["ExchangeGuid"];
if (prop?.Value == null)
throw new Exception($"ExchangeGuid was not returned for {upn}");
if (prop.Value is Guid guid)
return guid;
if (Guid.TryParse(prop.Value.ToString(), out Guid parsed))
return parsed;
throw new Exception($"ExchangeGuid value was not a valid Guid for {upn}: {prop.Value}");
}This avoids returning the full mailbox object and prevents the object transformation failure.
Recommended implementation
public Guid GetExchangeOnlineGuid(string upn, bool returnError)
{
ExchangeResourceOnline eol =
Evaluator.GetObject("=//Resources/Exchange Servers/Office365") as ExchangeResourceOnline;
if (eol == null)
throw new Exception("Could not find Exchange Online resource at =//Resources/Exchange Servers/Office365");
try
{
foreach (PSObject o in eol.Exec(
"Get-EXOMailbox",
"Identity", upn,
"Properties", new[] { "ExchangeGuid" }))
{
var value = o.Properties["ExchangeGuid"]?.Value;
if (value == null)
throw new Exception($"ExchangeGuid was not returned for {upn}");
if (value is Guid guid)
return guid;
if (Guid.TryParse(value.ToString(), out Guid parsed))
return parsed;
throw new Exception($"ExchangeGuid value was not a valid Guid for {upn}: {value}");
}
}
catch (Exception ex)
{
if (returnError)
throw new Exception($"Error retrieving ExchangeGuid for {upn}", ex);
}
return Guid.Empty;
}Notes
Use the property name:
Avoid:
Although PowerShell command-line property access is generally case-insensitive, C# PSObject.Properties[...] lookups should use the exact returned property name.
Validation steps
- Run the updated lookup using Get-EXOMailbox.
- Confirm the command requests only the required property:
- Confirm the result contains ExchangeGuid.
- Confirm the workflow no longer throws the InputObject transformation error.
- Confirm the returned GUID matches the mailbox’s Exchange GUID.
Outcome
Changing the lookup from full Get-Mailbox output to Get-EXOMailbox with only the required ExchangeGuid property reduced the response size and resolved the transformation failure.