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: Tue, 8 Jan 2008 09:20:31 -0500,    group: microsoft.public.exchange.development        back       


Exchange 2007 - Getting mailbox size from enterprise service   
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: Tue, 8 Jan 2008 09:20:31 -0500   author:   Brian Clayton

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

Google
 
Web ureader.com


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