Hide mailbox from .net
Nov 5, 2012

For Hide mailbox by .net : ICollection results; // Create a runspace. RunspaceConfiguration rc = RunspaceConfiguration.Create(); PSSnapInException snapEx = null; PSSnapInInfo info = rc.AddPSSnapIn( “Microsoft.Exchange.Management.PowerShell.Admin”, out snapEx); Runspace myRunSpace = RunspaceFactory.CreateRunspace(rc); myRunSpace.Open(); // Create a pipeline… Pipeline pipeLine = myRunSpace.CreatePipeline();
using (pipeLine) { // Create a command object so we can set some parameters // for this command. Command newMbx = new Command("Set-mailbox"); newMbx.Parameters.Add("Identity", name); // Name of MaileBox i.e domain name of User. newMbx.Parameters.Add("HiddenFromAddressListsEnabled", true);
 // Execute the pipeline and save the objects returned.
results = pipeLine.Invoke();
// Print out any errors in the pipeline execution
 // NOTE: These error are NOT thrown as exceptions!
 // Be sure to check this to ensure that no errors
 // happened while executing the command.
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
 foreach (object item in pipeLine.Error.ReadToEnd())
// throw new InValidDirectorySyntext(item.ToString());
pipeLine = null;
 myRunSpace = null;
For UnHide mail box you need to put newMbx.Parameters.Add(“HiddenFromAddressListsEnabled”, false); Namespace : using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Management.Automation.Host;ICollection results; Hope this will be help while you doing Exchange server communication from .net

Leave a Reply

Your email address will not be published. Required fields are marked *



Copyright © Prakash Software Solutions Pvt. Ltd. All Rights Reserved.