views:

3191

answers:

4

I'm having troubles using the Microsoft.Exchange.Management.PowerShell.Admin on a server. The server is not the one running Exchange 2007, it's a remote server (in the same zone). I can't figure out how to add the Snapin for Powershell - Microsoft.Exchange.Management.PowerShell.Admin. Is it possible to just get the dll file from the Exchange 2007 server, and copy it to the server where my code is running?

Can someone please explain what I need to do to get my code running?

The exception that i'm getting now is: "No Windows PowerShell Snap-ins are available for version 1". This is the code that generates the error:

public void CreateMailBox(User user)
        {            
            //Create a runspace for your cmdlets to run and include the Exchange Management SnapIn...

            RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
            PSSnapInException PSException = null;
            PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
            Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);

            runspace.Open();

            Pipeline pipeline = runspace.CreatePipeline();
            Command command = new Command("New-Mailbox");

            command.Parameters.Add("Name", user.UserName);

....

The error is coming on the line with PSSnapInfo info = runspaceConf..... I'm using .NET 3.5

A: 

I doubt that it is sufficient to just grab the one dll. And even if it is just the one DLL, will the snapin support remote operations? Eithe way, you still need to "install" the snapin so that PowerShell sees it e.g.:

PS> $snapinPath = 'Microsoft.Exchange.Management.PowerShell.Admin.dll'
PS> C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /i $snapinPath

If you want to do this remotely and you happen to be using PowerShell 2.0 then try out the remoting features. It would probably be better to run the snapin via a remote session to the Exchange server.

Keith Hill
Is there some place i can download theese files?
Svein Erik
InstallUtil is on your machine if you have PowerShell installed. It is in "$env:windir\Microsoft.NET\Framework\v2.0.50727". Not sure where to get the exchange snapin DLL except from MS Exchange Server.
Keith Hill
I ended up downloading the Exchange 2007 Management tools for 32bit. And all my code is running as it should, it creates the mailboxes perfectly on the remote Exchange server.BUT !!!!Now, I'm copying the programfiles of my app over to another server, where it's supposed to run. This is a x64 OS, and it has the Exchange Mngmt tools (x64), and Powershell installed. When I open Powershell, i can see that the Microsoft.Exchange.Management.PowerShell.Admin snapin is available in the x64 version of PowSh, but not in the 32bit PowSh. I get an error, seems like it's trying to load the 32bit.*sigh*
Svein Erik
Assuming your built your .NET assembly as AnyCPU you can register it in either 32-bit or 64-bit PowerShell. You do this by making sure to use the right instance of InstallUtil.exe. The 64-bit one is in c:\windows\microsoft.net\framework64\vx.x.xxxx. I would pick whichever bitness is compatible with the Exchange server snapin.
Keith Hill
A: 

I believe the Exchange 2007 snapin is a 32-bit DLL. I'm not a professional programmer, but how about trying to create your program as a 32-bit app?

I'm thinking if you build your app as 32-bit, then it will use the 32-bit PowerShell engine, and be able to load the snapin properly.

Now, I'd not recommend trying to copy the DLL to other servers. You should be installing the Exchange admin tools on the server where you're developing your app.

Hope this helps... If not, post a comment below.

Marco Shaw
A: 

Seriously confused by this.

Exchange 2007 SP2 installed, says it has PowerShell v2.0 support, but this is NOT TRUE.

Still shows up as a PSVersion 1.0 and not 2.0 look below:

Name : microsoft.exchange.management.powershell.admin PSVersion : 1.0 Description : Admin Tasks for the Exchange Server

Draek
I bailed out on this one..Everything is working, exept making the aliases to the email. I do it manually on the few that requests this..
Svein Erik
A: 

Could you show how your code connects to the remote exchange2007 server and what configuration s and permissions are required. I attempting to write a very similar app. but from what I understood, the app. has to run on the exchange2007 server.

toto