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:
PowerShell