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
  1. Home
  2. General Programming
  3. C#
  4. C#, Powershell, and Exchange

C#, Powershell, and Exchange

Scheduled Pinned Locked Moved C#
csharphtmlcomsysadminwindows-admin
2 Posts 2 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.
  • A Offline
    A Offline
    AGTCooke
    wrote on last edited by
    #1

    If this is the wrong place to post this question, please move it. There's lots of overlap, so I wasn't sure where to put it. Background: I'm trying to write a simple web application in C# that utilizes the Exchange Management Shell (EMS, 2007), which is itself a Windows Powershell snapin. I found a nice wrapper at here[^], which is what I'm using thus:

    public void AD_SetForwardAddress()
    {
    //Initialize the ExchangeManagementShellWrapper
    ExchangeManagementShellWrapper ems = ExchangeManagementShellWrapper.Instance;
    ICollection<PSObject> results;

    //Use the RunspaceInvoke command with a command string
    results = ems.RunspaceInvoke("Get-Command");
    foreach (PSObject item in results)
    {
        Response.Write(item.Members\["Name"\].Value.ToString());
    }
    

    }

    ... which yeilds

    Server Error in '/' Application.
    Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Management.Automation.Runspaces.PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.]
    System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) +3816533
    System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) +95
    System.Management.Autom

    M 1 Reply Last reply
    0
    • A AGTCooke

      If this is the wrong place to post this question, please move it. There's lots of overlap, so I wasn't sure where to put it. Background: I'm trying to write a simple web application in C# that utilizes the Exchange Management Shell (EMS, 2007), which is itself a Windows Powershell snapin. I found a nice wrapper at here[^], which is what I'm using thus:

      public void AD_SetForwardAddress()
      {
      //Initialize the ExchangeManagementShellWrapper
      ExchangeManagementShellWrapper ems = ExchangeManagementShellWrapper.Instance;
      ICollection<PSObject> results;

      //Use the RunspaceInvoke command with a command string
      results = ems.RunspaceInvoke("Get-Command");
      foreach (PSObject item in results)
      {
          Response.Write(item.Members\["Name"\].Value.ToString());
      }
      

      }

      ... which yeilds

      Server Error in '/' Application.
      Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.Management.Automation.Runspaces.PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.

      Source Error:

      An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

      Stack Trace:

      [PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.Admin because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.]
      System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) +3816533
      System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) +95
      System.Management.Autom

      M Offline
      M Offline
      Migounette
      wrote on last edited by
      #2

      My two cents: Certainly a privilieged account with exchange permission problem.

      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