Posts
49
Comments
83
Trackbacks
0
December 2008 Entries
Running scripts that only work under 32bit cleanly in 64bit PowerShell

The scenario is as following: you have some script that can only work in 32bit powershell (the COM objects it calles only work in 32 bit for example) but you are used to running 64bit powershell. So what to do you do? Easy, just write your script to check if its being called from a 32bit process and if not, spawn a copy of 32bit powershell to run itself! Tha way you never have to think about calling 32bit powershell explicitly.

Here is the snippet:

   1: if ($env:Processor_Architecture -ne "x86")
   2: {
   3:         write-warning "Running x86 PowerShell..."
   4:         &"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -noninteractive 
   5:              -noprofile -file $myinvocation.Mycommand.path -executionpolicy bypass
   6:         exit
   7: }
   8:  
   9: # rest of your code

 

Turns out I use this trick all the time as I frequently work with COM objects such as Office Charting Components which are only 32bit.

Technorati Tags:
posted @ Wednesday, December 03, 2008 12:08 AM | Feedback (1)
News
A little slow these days as I'm busy working on exchangelabs.com. I will try and post tidbits when I get some time. Enjoy the older posts till then!