Get-Mailbox fails with InputObject argument transformation error in Exchange Online
10 min
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 get mailbox identity 'user\@domain com' 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 rps exec("get mailbox", "identity", upn) 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 exchangeguid avoid exchangeguid 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 get exomailbox identity user\@domain com properties exchangeguid 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