Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. powershell command automation

powershell command automation

Scheduled Pinned Locked Moved ASP.NET
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deepak__sharma
    wrote on last edited by
    #1

    I m trying to run the following code on Exchange Server 2007 on a 64 bit server through asp.net 3.5 :- private bool fncCreateForwarding(string ruleName, string recipientEmaillID, string forwardingEmailID) { /* * New-JournalRule -Name "Discovery Journal Recipients" -Recipient * discovery@contoso.com -JournalEmailAddress "Journal Mailbox" * -Scope Global -Enabled $True */ bool _created = false; try { string _command = string.Empty; _command = "New-JournalRule"; string _result = string.Empty; Runspace myRunspace = RunspaceFactory.CreateRunspace(); myRunspace.Open(); 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 pipeLineEnable = myRunSpace.CreatePipeline(); Command myCommand = new Command(_command); myCommand.Parameters.Add("Name", ruleName); myCommand.Parameters.Add("Recipient", recipientEmaillID); myCommand.Parameters.Add("JournalEmailAddress", forwardingEmailID); myCommand.Parameters.Add("Scope", "Global"); myCommand.Parameters.Add("Enabled", true); pipeLineEnable.Commands.Add(myCommand); Collection commandResults = pipeLineEnable.Invoke(); _created = true; } catch (Exception ex) { Logger.LogError(ex); } return _created; } I have set the Active Solution Platform as Any CPU from the configuration manager. The problem is that nothing happens. The code executes without throwing any exception. But the Journaling Rule does not get created. Although when I run the command via Exchange Management Shell the command executes and creates Journaling rule. I would also like to tell that the same code is running perfectly on the other exchange server, but not on the Production server. What can be the problem? Warm regards Deepak Sharma

    D 1 Reply Last reply
    0
    • D deepak__sharma

      I m trying to run the following code on Exchange Server 2007 on a 64 bit server through asp.net 3.5 :- private bool fncCreateForwarding(string ruleName, string recipientEmaillID, string forwardingEmailID) { /* * New-JournalRule -Name "Discovery Journal Recipients" -Recipient * discovery@contoso.com -JournalEmailAddress "Journal Mailbox" * -Scope Global -Enabled $True */ bool _created = false; try { string _command = string.Empty; _command = "New-JournalRule"; string _result = string.Empty; Runspace myRunspace = RunspaceFactory.CreateRunspace(); myRunspace.Open(); 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 pipeLineEnable = myRunSpace.CreatePipeline(); Command myCommand = new Command(_command); myCommand.Parameters.Add("Name", ruleName); myCommand.Parameters.Add("Recipient", recipientEmaillID); myCommand.Parameters.Add("JournalEmailAddress", forwardingEmailID); myCommand.Parameters.Add("Scope", "Global"); myCommand.Parameters.Add("Enabled", true); pipeLineEnable.Commands.Add(myCommand); Collection commandResults = pipeLineEnable.Invoke(); _created = true; } catch (Exception ex) { Logger.LogError(ex); } return _created; } I have set the Active Solution Platform as Any CPU from the configuration manager. The problem is that nothing happens. The code executes without throwing any exception. But the Journaling Rule does not get created. Although when I run the command via Exchange Management Shell the command executes and creates Journaling rule. I would also like to tell that the same code is running perfectly on the other exchange server, but not on the Production server. What can be the problem? Warm regards Deepak Sharma

      D Offline
      D Offline
      deepak__sharma
      wrote on last edited by
      #2

      I sorted out the problem. The problem was of Application Pool in IIS, I created a separate pool and gave the Administrator user credentials. Thats it :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups