-1

I have written a powershell script and send to my team mates.

One of my teammate when he was right click and [Run with powershell] execute the script it did not work.

He told that it is Win7 64 bit machine.

Then i manually opened 32 bit Powershell and use the "Powershell -file <Filename>" and executed.

In 64 bit environment, can't we simply execute by right click and Run with powershell?

Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230
  • @Christian: I am using PowerCLI snapin. This is my first line "Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue". I applied your answer but still it fails. When i right click and run with powershell it vanish. (if i run in Powershell_ise , it simply says failed) – Samselvaprabu Apr 03 '12 at 12:07
  • the command 'Add-PSSnapin VMware.VimAutomation.Core' run in console works? – CB. Apr 03 '12 at 12:21
  • 1
    What's the (recursive) content of the registry key `HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1`? – Richard Apr 03 '12 at 15:35

1 Answers1

4

If for some reason your script can run only in x86 architecture add this at start in your script:

if ($env:Processor_Architecture -ne "x86")   
 {
      write-warning "Running PowerShell x86"   
         &"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -noninteractive -noprofile -file $myinvocation.Mycommand.path -executionpolicy bypass   
         exit   
}
CB.
  • 58,865
  • 9
  • 159
  • 159
  • http://stackoverflow.com/questions/4647429/powershell-on-windows-7-set-executionpolicy-for-regular-users Actual problem was as same as mentioned in the link. It solved my issue. – Samselvaprabu Apr 10 '12 at 07:07