header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Unified Messaging enabling/disabling with .NET C#
Last Post 21 Aug 2008 05:38 PM by dyger. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
dygerUser is Offline
New Member
New Member
Posts:2

--
18 Aug 2008 04:36 PM  

Hello,

I have developed some web services in .net that allow users to auto provision their own Email accounts in Exchange. Users can create, enable, and disable their own user accounts and resources. I have based my code on examples using resources such as:

http://knicksmith.blogspot.com/2007/03/managing-exchange-2007-recipients-with.html

I am sure you are aware of this and other resources.

My web services work great; however, I am trying to incorporate Unified Messaging enabling/disabling into my web services. I assumed it would work just like the normal exchange cmdlets, but every time I try to execute a Unified Messaging cmdlet from .net c# I get this error message:

System.Management.Automation.CmdletInvocationException: Unable to find assembly 'Microsoft.Exchange.Data.Directory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. ---> System.Runtime.Serialization.SerializationException: Unable to find assembly 'Microsoft.Exchange.Data.Directory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()

   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)

   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)

   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)

   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()

   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)

   at Microsoft.Exchange.Data.CloneHelper.SerializeObj(Object o)

   at Microsoft.Exchange.Data.Directory.ADRawEntry.Clone()

   at Microsoft.Exchange.UM.Rpc.UMRpcRequest..ctor(ADUser user)

   at Microsoft.Exchange.UM.Rpc.ValidateOrGeneratePINRequest..ctor(ADUser user)

   at Microsoft.Exchange.UM.Management.Tasks.UMMailboxTask.ValidateOrGeneratePIN(String pin)

   at Microsoft.Exchange.UM.Management.Tasks.EnableUMMailbox.DoValidate()

   at Microsoft.Exchange.UM.Management.Tasks.UMMailboxTask.InternalValidate()

   at Microsoft.Exchange.Configuration.Tasks.Task.ProcessRecord()

   at System.Management.Automation.Cmdlet.DoProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

   --- End of inner exception stack trace ---

   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)

   at System.Management.Automation.Internal.PipelineProcessor.Execute(Array input)

   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()

   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()

I don’t know why it is not finding the assembly. I found it myself on the server in the folder:

C:\Program Files\Microsoft\Exchange Server\Bin

I tried installing the assembly to the Global assembly directory: C:\WINDOWS\assembly

But then the Exchange management powershell snapin  (Microsoft.Exchange.Management.PowerShell.Admin) will not load at all.

I then tried adding the assembly as a reference directly in my code, but then I get this error message:

System.Management.Automation.CmdletInvocationException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.

   at Microsoft.Exchange.UM.Management.Tasks.UMMailboxTask.ValidateOrGeneratePIN(String pin)

   at Microsoft.Exchange.UM.Management.Tasks.EnableUMMailbox.DoValidate()

   at Microsoft.Exchange.UM.Management.Tasks.UMMailboxTask.InternalValidate()

   at Microsoft.Exchange.Configuration.Tasks.Task.ProcessRecord()

   at System.Management.Automation.Cmdlet.DoProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

   --- End of inner exception stack trace ---

   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)

   at System.Management.Automation.Internal.PipelineProcessor.Execute(Array input)

   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()

   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()

Has anyone done Unified Messaging cmdlets with .net? Does anyone know how to get it to work in .net or be able to tell me what I am doing wrong? The other exchange cmdlets work great, and the UM cmdlets work fine directly from powershell. Thanks for your help.

smurawskiUser is Offline
New Member
New Member
Posts:45

--
19 Aug 2008 11:32 PM  
I don't have much experience with Unified Messaging, but I'd be willing to look at your code to try to figure this out.
You should not have to add a reference to the assemblies in your code, as that will be available to PowerShell after adding the snapin when you create the runspace for the commands. I looked through the referenced samples and am willing to give it a shot. I'll set up an Exchange 2007 Server at home to try this out.
dygerUser is Offline
New Member
New Member
Posts:2

--
21 Aug 2008 05:38 PM  

Sure, your help would be appreciated.

So here is my code for enabling unified Messaging:

(ExchangeManagementShellWrapper class provided from the link above)

public string enableUnifiedMessaging(string accountId, string extension)
        {
            try
            {
        
            ExchangeManagementShellWrapper ems = new ExchangeManagementShellWrapper();

            Collection commandsList = new Collection();

            Command getUser = new Command("Get-User");
            getUser.Parameters.Add("Identity", domain + "\\" + accountId);

            commandsList.Add(getUser);

            Command enableUM = new Command("Enable-UMMailbox");
            enableUM.Parameters.Add("PinExpired", true);
            enableUM.Parameters.Add("UMMailboxPolicy", "Default Policy");
            enableUM.Parameters.Add("Extensions", extension);

            commandsList.Add(enableUM);

            PipelineReader errors;
            ICollection results = ems.PipelineInvoke(commandsList, out errors);

            //Process errors
            string errorMsg = "";

            if (errors.Count > 0)
            {

                foreach (object obj in errors.ReadToEnd())
                {

                    errorMsg += "Fail: " + obj.ToString();

                }
                return errorMsg;
            }

            return "OK - Unified Messaging for " + accountId + " was enabled successfully";

            }
            catch (Exception e)
            {
                return "ERROR: " + e.ToString();
            }
        }

I ran this powershell command from .net:

    [appdomain]::currentdomain.getassemblies()

And it showed that the assembly Microsoft.Exchange.Data.Directory was in fact loaded, yet the UM cmdlet fails because it says it cannot find the assembly. Could this possibly be a bug on Microsofts end?

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer