none
[E2007][PS][C#] Mail-Enable Public Folder With A Service RRS feed

  • Question

  • Hey everybody,

    as a student in my last year I'm currently busy with my internship. One of my assignments is to make a Windows service that automatically makes a public folder mail-enable.

    To do this, I thought of using Powershell. The service I've made executes the Powershell-command from within itself, only this doesn't work. The log that the service makes shows that everything goes as planned, and that it executes the Powershell but the folder isn't mail-enabled.


    Code:

    string script;
    PowerShell ps = PowerShell.Create();
    
    //text is path to the public folder
    //Variabele.serverIp contains the ip-address of the Exchange-server
    script = "Enable-MailPublicFolder -Identity " + "\"" + text + "\"" + " -Server " + "\"" + Variabele.serverIp + "\"";
    ps.AddScript(script);
    ps.Invoke();
    

    The service runs as Local System. Does my service need more rights so it can execute the Powershell? Or isn't it possible to make a service execute Powershell?

    If anybody has a better method to do this, I'd like to hear it.

    Thanks in advance,

    Pieter-Jan.

     

    PS: excuse my for my bad English...

    Monday, March 21, 2011 1:34 PM

Answers

  • Unless there's more code than what you provided, you cannot run an Exchange cmdlet from within a standard Powershell environment - you must first load the Exchange Mgnt Shell's provider.  If this is not the problem, then I suspect that your technique to 'runas' another user within the service is not doing what you think it's doing.

     

    And I do not know if EWS has a built-in function to do what you want.  If not, you're going to need to simply spend more time inside your service.  Did you write your code so that you could run the service's exe from a cmd prompt?  This always makes debugging service code much easier...

     

    Rob

     

    Tuesday, March 22, 2011 6:43 PM

All replies

  • Your thought about needing more rights is probably correct.  Each Exchange cmdlet's help text tells you what kinds of permissions are required - here's what happens when I execute Get-Help Enable-MailPublicFolder:

     

    To run the Enable-MailPublicFolder cmdlet, the account you use must be delegated the following:

    * Exchange Public Folder Administrator role and local Administrators group for the target server

     

    Local System won't have those rights, so you'll have to runas someone else.

     

    Rob

     

    Monday, March 21, 2011 7:58 PM
  • Thanks for your reply! I just tried it, but it didn't work...

    Maybe I'm on a dead trail with Powershell. Is it possible to make a public folder mail-enabled using the Exchange web services?

    Tuesday, March 22, 2011 10:00 AM
  • Unless there's more code than what you provided, you cannot run an Exchange cmdlet from within a standard Powershell environment - you must first load the Exchange Mgnt Shell's provider.  If this is not the problem, then I suspect that your technique to 'runas' another user within the service is not doing what you think it's doing.

     

    And I do not know if EWS has a built-in function to do what you want.  If not, you're going to need to simply spend more time inside your service.  Did you write your code so that you could run the service's exe from a cmd prompt?  This always makes debugging service code much easier...

     

    Rob

     

    Tuesday, March 22, 2011 6:43 PM
  • Using EMS cmdlets in powershell is generally going to be the best solution as Rob has pointed out you will need to run the cmdlet with a user that has specific rights you also need to add the EMS snap-in into the session your trying to use see http://msdn.microsoft.com/en-us/library/bb332449%28v=exchg.80%29.aspx

    You can also use EWS to Mail Enable a folder as well by setting a few extended properties see http://gsexdev.blogspot.com/2009/05/mail-enabling-public-folder-with-ews.html for a sample

    Cheers
    Glen 

    Wednesday, March 23, 2011 4:12 AM