static private GetCommand ( |
||
cmdInfo | ||
config | ||
Résultat | System.Management.Automation.Runspaces.Command |
/// <summary> /// Gets the Exchange user using powershell Get-User command /// </summary> /// <param name="cmdInfo">command info to get the user</param> /// <param name="attributes">attributes containing the Name</param> /// <returns><see cref="PSObject"/> with user info</returns> private PSObject GetUser(ExchangeConnector connector, PSExchangeConnector.CommandInfo cmdInfo, Name nameAttribute) { ExchangeConfiguration configuration = connector.Configuration; // assert we have user name string name = nameAttribute.GetNameValue(); ExchangeUtility.NullCheck(name, "User name", configuration); ICollection <ConnectorAttribute> attributes = new List <ConnectorAttribute>(); attributes.Add(nameAttribute); Command cmdUser = ExchangeUtility.GetCommand(cmdInfo, attributes, configuration); ICollection <PSObject> users = _helper.InvokePipeline(connector, cmdUser); if (users.Count == 1) { foreach (PSObject obj in users) { return(obj); } } throw new ArgumentException( configuration.ConnectorMessages.Format( "ex_bad_username", "Provided User name is not unique or not existing")); }
public void ExecuteQuery(ExecuteQueryContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: query={0}", context.Query); Command cmdGet = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetGetCommandName()), exconn.Configuration); if (context.Query != null) { cmdGet.Parameters.Add("Identity", context.Query); } ICollection <PSObject> objects; try { objects = _helper.InvokePipeline(exconn, cmdGet); } catch (ObjectNotFoundException e) { LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: got 'ObjectNotFound' exception ({0}), assuming suitable objects do not exist", e); return; } LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: got {0} objects", objects.Count); foreach (PSObject psobject in objects) { if (psobject != null) { context.ResultsHandler.Handle(_helper.CreateConnectorObject(exconn, psobject, context.ObjectClass)); } } }
public void Create(CreateOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; Command cmdNew = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetNewCommandName()), context.Attributes, exconn.Configuration); try { context.Uid = _helper.InvokePipelineAndGetGuid(exconn, cmdNew); } catch (ProxyAddressExistsException e) { // This is a tricky exception. Sometimes when creating an object that is already there (e.g. DistributionGroup), // PowerShell reports "ProxyAddressExists" instead of something like "ObjectExists" :( // So we have to distinguish these situations somehow... Name nameAttribute = ConnectorAttributeUtil.GetNameFromAttributes(context.Attributes); if (nameAttribute == null || nameAttribute.Value == null || nameAttribute.Value.Count() != 1) { LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "ProxyAddressExistsException reported; but no single-valued NAME attribute present -- reporting as is"); throw new ConnectorException(e.Message, e); } String name = (String)nameAttribute.Value[0]; LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "ProxyAddressExistsException reported; trying to see if object named " + name + " exists"); Command cmdGet = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetGetCommandName()), exconn.Configuration); cmdGet.Parameters.Add("Identity", name); ICollection <PSObject> objects; try { objects = _helper.InvokePipeline(exconn, cmdGet); } catch (ObjectNotFoundException e1) { objects = null; } if (objects == null || objects.Count == 0) { LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "...it does not -- reporting as is"); throw new ConnectorException(e.Message, e); } else { LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "...it exists -- reporting as AlreadyExistsException"); throw new AlreadyExistsException(e.Message, e); } } if (ExecuteSetAfterNew()) { Command cmdSet = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetSetCommandName()), context.Attributes, context.Uid, exconn.Configuration); try { _helper.InvokePipeline(exconn, cmdSet); } catch { // TODO rollback // rethrow original exception throw; } } }
public void Delete(DeleteOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; Command cmdRemove = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetRemoveCommandName()), context.Uid, exconn.Configuration); try { _helper.InvokePipeline(exconn, cmdRemove); } catch (ObjectNotFoundException e) { throw new UnknownUidException("Object with UID " + context.Uid.GetUidValue() + " couldn't be deleted", e); } }
public void Update(UpdateOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; ICollection <ConnectorAttribute> attributesForReplace = _helper.DetermineNewAttributeValues(context, context.Uid.GetUidValue()); // query string is the UID value! Command cmdSet = ExchangeUtility.GetCommand( new PSExchangeConnector.CommandInfo(GetSetCommandName()), attributesForReplace, context.Uid, exconn.Configuration); try { _helper.InvokePipeline(exconn, cmdSet); } catch (ObjectNotFoundException e) { throw new UnknownUidException("Object with UID " + context.Uid.GetUidValue() + " couldn't be modified", e); } }
/// <summary> /// Gets the Exchange user using powershell Get-User command /// </summary> /// <param name="cmdInfo">command info to get the user</param> /// <param name="attributes">attributes containing the Name</param> /// <returns><see cref="PSObject"/> with user info</returns> private PSObject GetUser(PSExchangeConnector.CommandInfo cmdInfo, ICollection <ConnectorAttribute> attributes) { // assert we have user name string name = ExchangeUtility.GetAttValue(Name.NAME, attributes) as string; ExchangeUtility.NullCheck(name, "User name", this.configuration); Command cmdUser = ExchangeUtility.GetCommand(cmdInfo, attributes, this.configuration); ICollection <PSObject> users = this.InvokePipeline(cmdUser); if (users.Count == 1) { foreach (PSObject obj in users) { return(obj); } } throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_bad_username", "Provided User name is not unique or not existing")); }
/// <summary> /// Implementation of CreateOp.Create /// </summary> /// <param name="oclass">Object class</param>(oc /// <param name="attributes">Object attributes</param> /// <param name="options">Operation options</param> /// <returns><see cref="Uid"/> of the created object</returns> public override Uid Create( ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options) { const string METHOD = "Create"; Debug.WriteLine(METHOD + ":entry", ClassName); // first create the object in AD Uid uid = base.Create(oclass, attributes, options); try { if (oclass.Is(MailboxName)) { // enable mailbox for person Command cmd = ExchangeUtility.GetCommand(CommandInfo.EnableMailbox, attributes, this.configuration); this.runspace.InvokePipeline(cmd); } else if (oclass.Is(MailUserName)) { // enable mailuser Command cmd = ExchangeUtility.GetCommand(CommandInfo.EnableMailUser, attributes, this.configuration); this.runspace.InvokePipeline(cmd); } Debug.WriteLine(METHOD + ":exit", ClassName); } catch { // do the rollback - delete the object by uid // no need to check the uid is null, ensured by the create contract this.Delete(oclass, uid, options); throw; } return(uid); }
/// <summary> /// Gets Recipient Type/Database from Exchange database, this method can be more general, but it is ok /// for out needs /// </summary> /// <param name="oc">object class, currently the moethod works for <see cref="ObjectClass.ACCOUNT"/> only</param> /// <param name="cobject">connector object to get the recipient type/database for</param> /// <param name="attToGet">attributes to get</param> /// <returns>Connector Object with recipient type added</returns> /// <exception cref="ConnectorException">In case of some troubles in powershell (if the /// user is not found we get this exception too)</exception> private ConnectorObject AddExchangeAttributes(ObjectClass oc, ConnectorObject cobject, IEnumerable <string> attToGet) { ExchangeUtility.NullCheck(oc, "name", this.configuration); ExchangeUtility.NullCheck(oc, "cobject", this.configuration); // we support ACCOUNT only or there is nothing to add if (!oc.Is(ObjectClass.ACCOUNT_NAME) || attToGet == null) { return(cobject); } // check it is not deleted object bool?deleted = ExchangeUtility.GetAttValue(AttIsDeleted, cobject.GetAttributes()) as bool?; if (deleted != null && deleted == true) { // do nothing, it is deleted object return(cobject); } ICollection <string> lattToGet = CollectionUtil.NewCaseInsensitiveSet(); CollectionUtil.AddAll(lattToGet, attToGet); foreach (string att in attToGet) { if (cobject.GetAttributeByName(att) != null && att != AttDatabase) { lattToGet.Remove(att); } } if (lattToGet.Count == 0) { return(cobject); } ConnectorObjectBuilder cobjBuilder = new ConnectorObjectBuilder(); cobjBuilder.AddAttributes(cobject.GetAttributes()); PSExchangeConnector.CommandInfo cmdInfo = PSExchangeConnector.CommandInfo.GetUser; // prepare the connector attribute list to get the command ICollection <ConnectorAttribute> attributes = new Collection <ConnectorAttribute> { cobject.Name }; // get the command Command cmd = ExchangeUtility.GetCommand(cmdInfo, attributes, this.configuration); ICollection <PSObject> foundObjects = this.InvokePipeline(cmd); PSObject user = null; if (foundObjects != null && foundObjects.Count == 1) { user = GetFirstElement(foundObjects); foreach (var info in user.Properties) { ConnectorAttribute att = GetAsAttribute(info); if (att != null && lattToGet.Contains(att.Name)) { cobjBuilder.AddAttribute(att); lattToGet.Remove(att.Name); } } if (lattToGet.Count == 0) { return(cobjBuilder.Build()); } } if (user == null) { // nothing to do return(cobject); } string rcptType = user.Members[AttRecipientType].Value.ToString(); foundObjects = null; // get detailed information if (rcptType == RcptTypeMailBox) { foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailbox, attributes, this.configuration)); } else if (rcptType == RcptTypeMailUser) { foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailUser, attributes, this.configuration)); } if (foundObjects != null && foundObjects.Count == 1) { PSObject userDetails = GetFirstElement(foundObjects); foreach (var info in userDetails.Properties) { ConnectorAttribute att = GetAsAttribute(info); if (att != null && lattToGet.Contains(att.Name)) { cobjBuilder.AddAttribute(att); lattToGet.Remove(att.Name); } } } return(cobjBuilder.Build()); }
/// <summary> /// Implementation of UpdateOp.Update /// </summary> /// <param name="type">Update type</param> /// <param name="oclass">Object class</param> /// <param name="attributes">Object attributes</param> /// <param name="options">Operation options</param> /// <returns>Uid of the updated object</returns> public override Uid Update( UpdateType type, ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options) { const string METHOD = "Update"; Debug.WriteLine(METHOD + ":entry", ClassName); ExchangeUtility.NullCheck(type, "updatetype", this.configuration); ExchangeUtility.NullCheck(oclass, "oclass", this.configuration); ExchangeUtility.NullCheck(attributes, "attributes", this.configuration); // we handle accounts only if (!oclass.Is(ObjectClass.ACCOUNT_NAME)) { return(base.Update(type, oclass, attributes, options)); } // get recipient type and database string rcptType = ExchangeUtility.GetAttValue(AttRecipientType, attributes) as string; string database = ExchangeUtility.GetAttValue(AttDatabase, attributes) as string; // update in AD first var filtered = FilterOut( attributes, PSExchangeConnector.CommandInfo.EnableMailbox, PSExchangeConnector.CommandInfo.EnableMailUser, PSExchangeConnector.CommandInfo.SetMailbox, PSExchangeConnector.CommandInfo.SetMailUser); Uid uid = base.Update(type, oclass, filtered, options); ConnectorObject aduser = this.ADSearchByUid(uid, oclass, ExchangeUtility.AddAttributeToOptions(options, AttDatabaseADName)); attributes.Add(aduser.Name); PSExchangeConnector.CommandInfo cmdInfo = PSExchangeConnector.CommandInfo.GetUser; if (aduser.GetAttributeByName(AttDatabaseADName) != null) { // we can be sure it is user mailbox type cmdInfo = PSExchangeConnector.CommandInfo.GetMailbox; } PSObject psuser = this.GetUser(cmdInfo, attributes); string origRcptType = psuser.Members[AttRecipientType].Value.ToString(); if (String.IsNullOrEmpty(rcptType)) { rcptType = origRcptType; } if (rcptType == RcptTypeMailUser) { if (type == UpdateType.REPLACE) { if (origRcptType != rcptType) { Command cmdEnable = ExchangeUtility.GetCommand( PSExchangeConnector.CommandInfo.EnableMailUser, attributes, this.configuration); this.InvokePipeline(cmdEnable); } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailUser, attributes, this.configuration); this.InvokePipeline(cmdSet); } else { throw new ConnectorException(this.configuration.ConnectorMessages.Format( "ex_wrong_update_type", "Update type [{0}] not supported", type)); } } else if (rcptType == RcptTypeMailBox) { // we should execute something like this here: // get-user -identity id|?{$_.RecipientType -eq "User"}|enable-mailbox -database "db" // unfortunately I was not able to get it working with the pipeline... that's why there are two commands // executed :-( // alternatively there can be something like: // get-user -identity id -RecipientTypeDetails User|enable-mailbox -database "db", but we have then trouble // with detecting attempt to change the database attribute string origDatabase = psuser.Members[AttDatabase] != null ? psuser.Members[AttDatabase].Value.ToString() : null; if (origRcptType != rcptType) { Command cmdEnable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.EnableMailbox, attributes, this.configuration); this.InvokePipeline(cmdEnable); } else { // trying to update the database? if (database != null && database != origDatabase) { throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_not_updatable", "Update of [{0}] attribute is not supported", AttDatabase)); } } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailbox, attributes, this.configuration); this.InvokePipeline(cmdSet); } else if (rcptType == RcptTypeUser && origRcptType != rcptType) { throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_update_notsupported", "Update of [{0}] to [{1}] is not supported", AttRecipientType, rcptType)); } else if (rcptType != RcptTypeUser) { // unsupported rcpt type throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", rcptType)); } Debug.WriteLine(METHOD + ":exit", ClassName); return(uid); }
/// <summary> /// Implementation of CreateOp.Create /// </summary> /// <param name="oclass">Object class</param>(oc /// <param name="attributes">Object attributes</param> /// <param name="options">Operation options</param> /// <returns>Uid of the created object</returns> public override Uid Create( ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options) { ExchangeUtility.NullCheck(oclass, "oclass", this.configuration); ExchangeUtility.NullCheck(attributes, "attributes", this.configuration); // we handle accounts only if (!oclass.Is(ObjectClass.ACCOUNT_NAME)) { return(base.Create(oclass, attributes, options)); } const string METHOD = "Create"; Debug.WriteLine(METHOD + ":entry", ClassName); // get recipient type string rcptType = ExchangeUtility.GetAttValue(AttRecipientType, attributes) as string; PSExchangeConnector.CommandInfo cmdInfoEnable = null; PSExchangeConnector.CommandInfo cmdInfoSet = null; switch (rcptType) { case RcptTypeMailBox: cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailbox; cmdInfoSet = PSExchangeConnector.CommandInfo.SetMailbox; break; case RcptTypeMailUser: cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailUser; cmdInfoSet = PSExchangeConnector.CommandInfo.SetMailUser; break; case RcptTypeUser: break; default: throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", rcptType)); } // first create the object in AD Uid uid = base.Create(oclass, FilterOut(attributes, cmdInfoEnable, cmdInfoSet), options); if (rcptType == RcptTypeUser) { // AD account only, we do nothing return(uid); } // prepare the command Command cmdEnable = ExchangeUtility.GetCommand(cmdInfoEnable, attributes, this.configuration); Command cmdSet = ExchangeUtility.GetCommand(cmdInfoSet, attributes, this.configuration); try { this.InvokePipeline(cmdEnable); this.InvokePipeline(cmdSet); } catch { Trace.TraceWarning("Rolling back AD create for UID: " + uid.GetUidValue()); // rollback AD create try { Delete(oclass, uid, options); } catch { Trace.TraceWarning("Not able to rollback AD create for UID: " + uid.GetUidValue()); // note: this is not perfect, we hide the original exception throw; } // rethrow original exception throw; } Debug.WriteLine(METHOD + ":exit", ClassName); return(uid); }
public void Create(CreateOpContext context) { context.Attributes = DeduplicateEmailAddresses(context, context.Attributes); // get recipient type string rcptType = ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttRecipientType, context.Attributes) as string; if (rcptType == null || rcptType.Equals("")) { rcptType = ExchangeConnectorAttributes.RcptTypeUser; } ExchangeConnector exconn = (ExchangeConnector)context.Connector; ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector; PSExchangeConnector.CommandInfo cmdInfoEnable = null; PSExchangeConnector.CommandInfo cmdInfoSet = null; switch (rcptType) { case ExchangeConnectorAttributes.RcptTypeMailBox: cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailbox; cmdInfoSet = PSExchangeConnector.CommandInfo.SetMailbox; break; case ExchangeConnectorAttributes.RcptTypeMailUser: cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailUser; cmdInfoSet = PSExchangeConnector.CommandInfo.SetMailUser; break; case ExchangeConnectorAttributes.RcptTypeUser: break; default: throw new ArgumentException( context.ConnectorConfiguration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", rcptType)); } // first create the object in AD ICollection <ConnectorAttribute> adAttributes = ExchangeUtility.FilterOut(context.Attributes, PSExchangeConnector.CommandInfo.EnableMailbox, PSExchangeConnector.CommandInfo.SetMailbox, PSExchangeConnector.CommandInfo.EnableMailUser, PSExchangeConnector.CommandInfo.SetMailUser); Uid uid = adconn.Create(context.ObjectClass, adAttributes, context.Options); if (rcptType == ExchangeConnectorAttributes.RcptTypeUser) { // AD account only, we do nothing context.Uid = uid; return; } // add a empty "EmailAddresses" attribute if needed (address policy is disabled and no addresses are provided) ICollection <ConnectorAttribute> enhancedAttributes; ConnectorAttribute policyEnabledAttribute = ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttEmailAddressPolicyEnabled, context.Attributes); if (policyEnabledAttribute != null && ConnectorAttributeUtil.GetBooleanValue(policyEnabledAttribute).HasValue&& ConnectorAttributeUtil.GetBooleanValue(policyEnabledAttribute).Value == false && ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttPrimarySmtpAddress, context.Attributes) == null && ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttEmailAddresses, context.Attributes) == null) { enhancedAttributes = new HashSet <ConnectorAttribute>(context.Attributes); enhancedAttributes.Add(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttEmailAddresses)); LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Added empty EmailAddresses attribute because address policy use is disabled and no addresses were provided"); } else { enhancedAttributes = context.Attributes; // no change } // prepare the command Command cmdEnable = ExchangeUtility.GetCommand(cmdInfoEnable, enhancedAttributes, uid, (ExchangeConfiguration)context.ConnectorConfiguration); Command cmdSet = ExchangeUtility.GetCommand(cmdInfoSet, enhancedAttributes, uid, (ExchangeConfiguration)context.ConnectorConfiguration); try { _helper.InvokePipeline(exconn, cmdEnable); _helper.InvokePipeline(exconn, cmdSet); } catch { LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Rolling back AD create for UID: " + uid.GetUidValue()); // rollback AD create try { adconn.Delete(context.ObjectClass, uid, context.Options); } catch { LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Not able to rollback AD create for UID: " + uid.GetUidValue()); // note: this is not perfect, we hide the original exception throw; } // rethrow original exception throw; } context.Uid = uid; }
public void Update(UpdateOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector; // update in AD first var filtered = ExchangeUtility.FilterOut( context.Attributes, PSExchangeConnector.CommandInfo.EnableMailbox, PSExchangeConnector.CommandInfo.EnableMailUser, PSExchangeConnector.CommandInfo.SetMailbox, PSExchangeConnector.CommandInfo.SetMailUser); adconn.Update(context.UpdateType, context.ObjectClass, context.Uid, filtered, context.Options); // retrieve Exchange-related information about the user string query = "(objectGUID=" + ActiveDirectoryUtils.ConvertUIDToSearchString(context.Uid) + ")"; ConnectorObject currentObject = _helper.GetCurrentObject(context, query); ICollection <ConnectorAttribute> attributesForReplace = _helper.DetermineNewAttributeValues(context, currentObject); attributesForReplace = DeduplicateEmailAddresses(context, attributesForReplace); string origRcptType; var newRcptType = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttRecipientType, out origRcptType); if (newRcptType == null) { newRcptType = ExchangeConnectorAttributes.RcptTypeUser; } string origDatabase; var newDatabase = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttDatabase, out origDatabase); // PART 1 - DEALING WITH MailUser CASE if (ExchangeConnectorAttributes.RcptTypeMailUser.Equals(newRcptType)) { // disabling Mailbox if needed if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailbox, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } // enabling MailUser if needed if (!ExchangeConnectorAttributes.RcptTypeMailUser.Equals(origRcptType)) { // Enable-MailUser needs the value of ExternalEmailAddress, so we have to get it string origExternalEmailAddress; var newExternalEmailAddress = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttExternalEmailAddress, out origExternalEmailAddress); if (String.IsNullOrEmpty(newExternalEmailAddress)) { throw new InvalidOperationException("Missing ExternalEmailAddress value, which is required for a MailUser"); } ExchangeUtility.SetAttValue(ExchangeConnectorAttributes.AttExternalEmailAddress, newExternalEmailAddress, attributesForReplace); // now execute the Enable-MailUser command Command cmdEnable = ExchangeUtility.GetCommand( PSExchangeConnector.CommandInfo.EnableMailUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdEnable); } // setting MailUser attributes Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } // PART 2 - DEALING WITH UserMailbox CASE else if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(newRcptType)) { // enable mailbox if necessary // we should execute something like this here: // get-user -identity id|?{$_.RecipientType -eq "User"}|enable-mailbox -database "db" // unfortunately I was not able to get it working with the pipeline... that's why there are two commands // executed :-( // alternatively there can be something like: // get-user -identity id -RecipientTypeDetails User|enable-mailbox -database "db", but we have then trouble // with detecting attempt to change the database attribute if (!ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdEnable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.EnableMailbox, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdEnable); } else { // are we trying to update the database? if (newDatabase != null && origDatabase != null && !newDatabase.Equals(origDatabase)) { throw new ArgumentException( context.ConnectorConfiguration.ConnectorMessages.Format( "ex_not_updatable", "Update of [{0}] attribute is not supported", ExchangeConnectorAttributes.AttDatabase)); } } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailbox, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } // PART 3 - DEALING WITH User CASE else if (ExchangeConnectorAttributes.RcptTypeUser.Equals(newRcptType)) { if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailbox, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } else if (ExchangeConnectorAttributes.RcptTypeMailUser.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailUser, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } else if (ExchangeConnectorAttributes.RcptTypeUser.Equals(origRcptType)) { // if orig is User, there is no need to disable anything } else { throw new InvalidOperationException("Invalid original recipient type: " + origRcptType); } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } else { // unsupported rcpt type throw new ArgumentException( context.ConnectorConfiguration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", newRcptType)); } }