powershell c#
- From: "Alex" <nospam@xxxxxxxxx>
- Date: Fri, 19 Oct 2007 09:24:25 +0200
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
.
- Prev by Date: DSAccess...
- Next by Date: Re: DSAccess...
- Previous by thread: DSAccess...
- Next by thread: Exchange 2003 Public Folders Permissions.
- Index(es):
Relevant Pages
|