Unable to add members with in a distribution list programmitically in Office 365

Hi All,

I am developing an application with visual studio, to create a new distribution list and then add members in this list. with the below code I am able to create the distribution list, but it is not adding the members in the list. Please note that I am adding the existing members (already in contact) in this list. Please have a look in the below code :

using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
            {
                runspace.Open();
                using (PowerShell powershell = PowerShell.Create())
                {

                    powershell.Runspace = runspace;
                    Command cmd = new Command("New-DistributionGroup");
                    cmd.Parameters.Add("Name", "Managers1");
                    cmd.Parameters.Add("IgnoreNamingPolicy");
                    cmd.Parameters.Add("MemberJoinRestriction", "Open");
                    
                    powershell.Commands.AddCommand(cmd);

                    cmd = new Command("Add-DistributionGroupMember");
                    cmd.Parameters.Add("Identity", "Managers1");
                    cmd.Parameters.Add("Member", "vinayshakti@yahoo.co.in");
                    cmd.Parameters.Add("BypassSecurityGroupManagerCheck");

                    powershell.Commands.AddCommand(cmd);
                    //Invoke the command and store the results in a PSObject collection
                    Collection<PSObject> results = powershell.Invoke();
                    //Iterate through the results and write the DisplayName and PrimarySMTP
                    //address for each mailbox
                    foreach (PSObject result in results)
                    {
                        //Console.WriteLine(string.Format("Name: {0}, PrimarySmtpAddress: {1}", result.Properties["DisplayName"].Value.ToString(), result.Properties["PrimarySmtpAddress"].Value.ToString()));
                    }
                }

            }

the above code is not giving me any exception however it is also not adding members with in the group.

I have also post this problem here : https://community.office365.com/en-us/f/172/t/404411

please  help me and let me know why is it not adding the member in the above created group.

Regards,

Vinay


August 21st, 2015 12:50pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics