How to add Powershell SnapIn in c# How to add Powershell SnapIn in c# powershell powershell

How to add Powershell SnapIn in c#


That error message also means that you are trying to load a 32bit snapin from a 64bit powershell instance (or vice-versa.) In your case, you need to compile your program to target the correct bitness: x86. AnyCPU will default to the bitness of your machine, which is 64 bit.


I had a similar issue... I was trying to execute a custom powershell cmdlet from a console application. I verified that my console is set to 4.0 framework and the powershell was 3.0. It turned out that the issue was "prefer 32 bit" setting in bild tab of the console was set to true. I unchecked it and everything worked!