Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:26:47+00:00 2026-06-03T12:26:47+00:00

I have an application which (among other things) needs to call the New-MailContact cmdlet

  • 0

I have an application which (among other things) needs to call the New-MailContact cmdlet and create contacts in Active Directory. I have followed a handful of tech articles to get as far as I have, but it is still not working.

I have verified my service account being used has the proper authentication based on this TechNet page. I am able to find and invoke the cmdlet from powershell, and I recieve no errors.

However, after running I inspect my OU and my contact was not created. I found this KB article which I think may be suspect, but since the cmdlet doesn’t return any errors after the invoke, I can’t be sure that this will solve my problem.

Here is a snippet of what I am doing:

    public bool CreateMailContactObject(ADExchangeContact adExchangeContacts)
    {
        Collection<PSObject> results;
        Pipeline pipeLine = null;

        try
        {
            var runspaceConfiguration = RunspaceConfiguration.Create();
            PSSnapInException snapInException;
            var snapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);

            using (var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
            {
                var newMailBoxContact = new Command("New-MailContact");
                newMailBoxContact.Parameters.Add("Name", adExchangeContacts.DisplayName);
                newMailBoxContact.Parameters.Add("ExternalEmailAddress", adExchangeContacts.ExternalEmailAddress);
                newMailBoxContact.Parameters.Add("OrganizationalUnit", adExchangeContacts.OrganizationalUnit);
                newMailBoxContact.Parameters.Add("Alias", adExchangeContacts.Alias);

                runspace.Open();

                pipeLine = runspace.CreatePipeline();
                pipeLine.Commands.Add(newMailBoxContact);

                results = pipeLine.Invoke();

                _log.DebugFormat("results.Count = {0}", results.Count);
                results.ForEach(x => x.Properties.ForEach(y => _log.DebugFormat("{0}: {1}", y.Name, y.Value)));

                pipeLine.Stop();
                runspace.Close();
            }

            return true;
        }
        catch (Exception ex)
        {
            // Add log statement
            _log.ErrorFormat("Creation of Mail Contact in AD Failed. Error: {0}", ex);
            return false;
        }            
    }

I do not get any exceptions, and my result list is empty from the Pipeline invoke. Is there something I am missing? If the cmdlet fails due to permissions when creating the contact in AD, wouldn’t I expect to recieve some sort of error in the result set from pipeLine.Invoke() ??

I am new with running Powershell, so if there is another issue (beyond the KB article) that could be at hand, please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:26:49+00:00Added an answer on June 3, 2026 at 12:26 pm
        if (pipeline.Error != null && pipeline.Error.Count > 0)
                    {
                        StringBuilder pipelineError = new StringBuilder();
                        pipelineError.AppendFormat("Error calling Add-MailboxPermission.");
                        foreach (object item in thisPipeline.Error.ReadToEnd())
                        {
                            pipelineError.AppendFormat("{0}\n", item.ToString());
                        }
    
                        ErrorText = ErrorText + "Error: " + pipelineError.ToString() + Environment.NewLine;
                    }
    

    Please Put this code after pipeline.Invoke() and check if there is any error in there

    Update:
    I think this is erro with giving right permission to user,some solutions for this:

    http://boardreader.com/thread/Microsoft_Exchange_2010_wont_allow_new_M_1w69j__37ad9f8a-cdcf-4d26-9384-00ad1a3d0f91.html
    http://blogs.technet.com/b/richardroddy/archive/2010/07/12/exchange-2010-and-the-exchange-trusted-subsystem.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application which, among other things, also publishes updates on Facebook.
I have an MVC application that among other things contains a small Silverlight menu
I am creating application in Winform which among other things will also need to
I have a data entry application, with (among other things) a textbox for recording
I'm working on an application which among other things downloads items that belong to
I have an embedded device which runs Java applications which can among other things
I have application which needs to use a dll (also written by me) which
We have an application which needs to use Direct3D. Specifically, it needs at least
I have an application which takes a string value of the form %programfiles%\directory\tool.exe from
Coding Language: C# Framework: .NET We have built a software, which among many other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.