Brian Clayton
2008-01-08 14:20:31 UTC
I am attempting to retrieve the mailbox size for a specified account using
PowerShell from a .NET enterprise service (running as a domain admin). The
same code works fine from a console application, but I always get an error
like "The specified mailbox database "..." does not exist" at the call to
invoke Get-MailboxStatistics from the enterprise service. Here is the code:
string totalItemSize = "";
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);
IList errors;
Collection<PSObject> commandResults =
ri.Invoke("Get-MailboxStatistics -Identity \"someuser\"", null, out errors);
foreach (PSObject cmdlet in commandResults)
{
totalItemSize = cmdlet.Properties["TotalItemSize"].Value.ToString();
}
Any ideas?
Thanks,
Brian
PowerShell from a .NET enterprise service (running as a domain admin). The
same code works fine from a console application, but I always get an error
like "The specified mailbox database "..." does not exist" at the call to
invoke Get-MailboxStatistics from the enterprise service. Here is the code:
string totalItemSize = "";
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);
IList errors;
Collection<PSObject> commandResults =
ri.Invoke("Get-MailboxStatistics -Identity \"someuser\"", null, out errors);
foreach (PSObject cmdlet in commandResults)
{
totalItemSize = cmdlet.Properties["TotalItemSize"].Value.ToString();
}
Any ideas?
Thanks,
Brian