1

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

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
Svein Erik
  • 531
  • 2
  • 11
  • 24

4 Answers4

1

It also depends on how the code is compiled in VS 2010 (x86 or x64). If you want to load the 64 Bit Exchange Server Snapin you have to compile with x64.

You can use $PsVersionTable to check if the PowerShell is version 2.0 (it should)

Pemo12
  • 61
  • 1
  • 8
0

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
  • 194,368
  • 42
  • 353
  • 369
  • Is there some place i can download theese files? – Svein Erik Sep 23 '09 at 19:48
  • 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 Sep 23 '09 at 20:48
  • 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 Sep 25 '09 at 10:58
  • 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 Sep 25 '09 at 23:05
0

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
  • 1,117
  • 6
  • 13
0

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
  • 1
  • 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 Apr 09 '10 at 10:28