So, I import the System.Management.Automation
dll and I'm trying to run a New-Mailbox
command with params
so I use:
RunspaceConfiguration config = RunspaceConfiguration.Create();
PSSnapInException psEx = null;
config.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out psEx);
That's all fine and dandy... but when I go to run the application I get the following:
Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.E2010 because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.
So, I did some research online and found that I need to change from Any CPU
to x86
as the platform target.
However, when I do that I get a HTTP Error 503. The service is unavailable.
error
I am almost positive that I have to run it as a 32 bit process so that it can use the snapin (which from other reading seems to be what the snapin is running under)
I did change the app pool to Enable 32-bit Applications
to True
. Which is when I get the error.
I've read other posts... but, I'm not sure how to get past this Service unavailable
thing.
I've tried using a x64 build and get Could not load file or assembly 'EmailAdminWeb2' or one of its dependencies. An attempt was made to load a program with an incorrect format.
You don't use this at all:
config.AddPSSnapIn("your snapin here", out psEx);
instead.... just use a connection as follows:
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://yourdomainhere/Powershell/Microsoft.Exchange"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", PsCreds);
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
Now run your commands and you're good to go.
Quick notes:
x64
not Any CPU
or x86
Enable 32bit apps
set to falseIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With