|
|
|
date: Tue, 8 Jan 2008 09:20:31 -0500,
group: microsoft.public.exchange.development
back
Re: Exchange 2007 - Getting mailbox size from enterprise service
Hi,
this won't work because some sort of impersonation issues... the same thing
happened with CDOEXM on Exchange 2003.
You need to seperate the logic from your ASP.NET application and put it in a
COM+ application. This way, the powershell code runs in a separate process.
If you need more info on this, feel free to drop me a mail. I should have
some code somewhere...
Kind regards,
Henning Krause
"Brian Clayton" wrote in message
news:ejQ9gGgUIHA.5160@TK2MSFTNGP05.phx.gbl...
>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
>
date: Wed, 9 Jan 2008 22:05:05 +0100
author: Henning Krause [MVP - Exchange]
Re: Exchange 2007 - Getting mailbox size from enterprise service
Hi,
just ignore my last post.... I didn't get that you are already working in a
COM+ application...
Henning
"Henning Krause [MVP - Exchange]"
wrote in message news:emSUSNwUIHA.2268@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> this won't work because some sort of impersonation issues... the same
> thing happened with CDOEXM on Exchange 2003.
>
> You need to seperate the logic from your ASP.NET application and put it in
> a COM+ application. This way, the powershell code runs in a separate
> process.
>
> If you need more info on this, feel free to drop me a mail. I should have
> some code somewhere...
>
> Kind regards,
> Henning Krause
>
> "Brian Clayton" wrote in message
> news:ejQ9gGgUIHA.5160@TK2MSFTNGP05.phx.gbl...
>>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
>>
>
date: Wed, 9 Jan 2008 22:16:24 +0100
author: Henning Krause [MVP - Exchange]
Re: Exchange 2007 - Getting mailbox size from enterprise service
Hi Brian,
I've just put your code into a serviced component:
[ProgId("Example.MailboxStatistics"), ComVisible(true)]
public class MailboxStatistics: ServicedComponent, IMailboxStatistics
{
public string GetMailboxSize(string username)
{
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException;
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin",
out snapInException);
using (Runspace myRunSpace =
RunspaceFactory.CreateRunspace(rsConfig))
{
myRunSpace.Open();
using (Pipeline pipeLine = myRunSpace.CreatePipeline())
{
Command command;
command = new Command("Get-MailboxStatistics");
command.Parameters.Add("Identity", username);
pipeLine.Commands.Add(command);
Collection<PSObject> commandResults = pipeLine.Invoke();
foreach (PSObject cmdlet in commandResults)
{
PSPropertyInfo value =
cmdlet.Properties["TotalItemSize"];
return value.Value.ToString();
}
return "nothing";
}
}
}
}
Just slight modifications to your code.... but It works when I put it in a
COM+ application and call it from a website.
Kind regards,
Henning Krause
"Brian Clayton" wrote in message
news:ejQ9gGgUIHA.5160@TK2MSFTNGP05.phx.gbl...
>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
>
date: Wed, 9 Jan 2008 23:12:37 +0100
author: Henning Krause [MVP - Exchange]
Re: Exchange 2007 - Getting mailbox size from enterprise service
Hi Henning,
Thanks very much for your response. In trying out your code, I realized what
I was doing wrong; I was using a static method (which of course uses the
caller's security context). Doh!
I changed it to an instance method and everything works great!
Thanks again,
Brian
"Henning Krause [MVP - Exchange]"
wrote in message news:%23oJMCzwUIHA.4532@TK2MSFTNGP02.phx.gbl...
> Hi Brian,
>
> I've just put your code into a serviced component:
>
> [ProgId("Example.MailboxStatistics"), ComVisible(true)]
> public class MailboxStatistics: ServicedComponent, IMailboxStatistics
> {
> public string GetMailboxSize(string username)
> {
> RunspaceConfiguration rsConfig =
> RunspaceConfiguration.Create();
> PSSnapInException snapInException;
>
>
> rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out
> snapInException);
>
> using (Runspace myRunSpace =
> RunspaceFactory.CreateRunspace(rsConfig))
> {
> myRunSpace.Open();
> using (Pipeline pipeLine = myRunSpace.CreatePipeline())
> {
> Command command;
>
> command = new Command("Get-MailboxStatistics");
> command.Parameters.Add("Identity", username);
>
> pipeLine.Commands.Add(command);
>
> Collection<PSObject> commandResults =
> pipeLine.Invoke();
>
> foreach (PSObject cmdlet in commandResults)
> {
> PSPropertyInfo value =
> cmdlet.Properties["TotalItemSize"];
> return value.Value.ToString();
> }
>
> return "nothing";
> }
> }
> }
> }
>
> Just slight modifications to your code.... but It works when I put it in a
> COM+ application and call it from a website.
>
> Kind regards,
> Henning Krause
date: Thu, 10 Jan 2008 10:50:19 -0500
author: Brian Clayton
|
|