views:

698

answers:

1

Microsoft appears to be moving a lot of configuration and query capabilities to PowerShell (accessible from C# or managed C++), while deprecating and even removing older APIs (accessible for C or unmanaged C++). Those of us who have extensive unmanaged C++ programs that can't switch to managed C++ may have a need to call PowerShell cmdlets (at least, I have one now) -- how can we do so?

There are suggestions that a reverse-PInvoke (managed/unmanaged thunking) might be able to do something, but I'm hoping for a better way than either thunking or parsing text output from a PowerShell script.

[Note: This is a reworked and generalized query I made yesterday that may have been too specialized.]

+2  A: 

The MS suggestion would probably be to compile specific classes/modules in your generally unmanaged C++ app as managed code (compiling individual files with /clr), and letting the IJW transition code manage the calls to/from it (and calling PowerShell API's from the managed bits). I've been told (from MS VC++ people) that's the expected methodology for adding bits of managed calls to large unmanaged applications.

Hope that helps.

Nick
Thanks. This suggestion gave me some interesting things to query, and we have a planned implementation based on what we found.
Austin Ziegler