How to let PowerShell x86 return an object while call powershell x86 cmdlet from powershell x64

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
ivan.liao@live.com
Posts: 15
Last visit: Wed Jan 19, 2022 4:49 pm

How to let PowerShell x86 return an object while call powershell x86 cmdlet from powershell x64

Post by ivan.liao@live.com »

Hi everyone here,

I'm currently developing a tools with PowerShell. I would like to let this tools run in PowerShell x64. But some of my action need to call a CmdLet in a DLL, but this dll does not has x64 version. I have to use PowerShell x86 to get this done and get the result. Something like this:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -command "& { Import $dll; Do-Someting }"
However, this method to call a dll returns result as string. How can I let it return the original object from CmdLet Do-Someting?

Thanks in advance!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to let PowerShell x86 return an object while call powershell x86 cmdlet from powershell x64

Post by jvierra »

You cannot return objects from external programs. You can only return strings. YOU could output XML and turn that into an object.

Get-Service spooler | convertto-xml
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked