Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Exchange
2000.active.directory
2000.admin
2000.announcements
2000.app.conversion
2000.applications
2000.clients
2000.clustering
2000.connectivity
2000.development
2000.documentation
2000.general
2000.information.store
2000.interop
2000.kms
2000.misc
2000.protocols
2000.realtime.collabo.
2000.setup
2000.transport
2000.win2000
admin
application.conversion
applications
clients
clustering
connectivity
design
development
misc
mobility
setup
tools
  
 
date: Fri, 19 Oct 2007 09:24:25 +0200,    group: microsoft.public.exchange2000.general        back       


powershell c#   
Hello,

I tried to execute a simple Exchange 2007 Powershell command in my C# code:

Get-MailboxStatistics -Identity TestUser1

This Command works well in the Powershell command window.

 According to the MSDN this should work like following:


--------------------------
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();

PSSnapInException snapInException = null;

PSSnapInInfo info = 
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out 
snapInException);

Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);

myRunSpace.Open();

Pipeline pipeLine = myRunSpace.CreatePipeline();


RunspaceInvoke ri = new RunspaceInvoke(myRunSpace);

Collection<PSObject> commandResults = 
ri.Invoke("Get-MailboxStatistics -Identity testuser1");

foreach (PSObject cmdlet in commandResults)

{

string cmdletName = cmdlet.Properties["DisplayName"].Value.ToString();

System.Diagnostics.Debug.Print(cmdletName);

}

------------------



But unfortunatly for some Users this command returns, that the mailbox could 
not be found, even though the command works well in the Powershell window. 
Where are differences in executing a command in the powershell window or in 
code???

Alex
date: Fri, 19 Oct 2007 09:24:25 +0200   author:   Alex

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us