Wrap ps1 to Exe to run on 32-bit PowerShell host only

by DexterPOSH at 2013-04-15 16:03:05

Hello Power Users,

I have a script which does some SCCM Client maintenance work. Now right now am calling this Script from a batch file using 32-bit PowerShell host.
But I thought why not compile it as an executable using PowerGUI (am on PowerShell v2 ).

But wait there’s one gotcha in this , few tasks in SCCM Client have a dependency on 32-bit PowerShell host that means when I try to instantiate the following COM object needed in the script from 64-bit host it throws an error.

PS C:> $cpappletmgr = New-Object -ComObject CPAPPLET.CPAppletMgr
New-Object : Retrieving the COM class factory for component with CLSID {096C5BA8-044B-4BAC-9914-144723BA4F2A} failed du
e to the following error: 80040154.
At line:1 char:26
+ $cpappletmgr = New-Object <<<< -ComObject CPAPPLET.CPAppletMgr
+ CategoryInfo : ResourceUnavailable: (:slight_smile: [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand


Now my question is Can I compile the script to an executable, that uses 32-bit PowerShell host on 64-bit machine.
It would be much appreciated if anyone can tell me how does the executable ends up running eventually after I compile it.


I have tried compiling it using the PowerGUI x86 Script Editor on 64-bit machine, but no luck. It uses the default 64-bit host.
by DonJ at 2013-04-15 16:07:15
Yeah. SCCM. WTF.

You can’t compile PowerShell scripts. It isn’t a compiled language. You can "package" it, which is what PowerGUI does. PrimalScript also does, and I believe PrimalScript offers the ability to select a host.
by DexterPOSH at 2013-04-22 18:18:12
Thanks Sir Don,

Sorry was a bit late in replying and I used the word "compile" as that was the option present in PowerGUI :slight_smile:
So in reality all these tools package the PS1…But I observed this packaged exe bypasses the execution policy in PowerShell (probably by using bypass as the exec’n policy while calling the PS1)