问题
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
回答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)
回答2:
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.
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/1467753/microsoft-exchange-management-powershell-admin