protected override void ExecuteCmdlet() { TaxonomyItem taxItem = null; Field field; if (ParameterSetName == "Path") { taxItem = ClientContext.Site.GetTaxonomyItemByPath(TermSetPath, TermPathDelimiter); } else { var taxSession = ClientContext.Site.GetTaxonomySession(); var termStore = taxSession.GetDefaultKeywordsTermStore(); try { taxItem = termStore.GetTermSet(TaxonomyItemId.Id); } catch { try { taxItem = termStore.GetTerm(TaxonomyItemId.Id); } catch { throw new Exception(string.Format("Taxonomy Item with Id {0} not found", TaxonomyItemId.Id)); } } taxItem.EnsureProperty(t => t.Id); } Guid id = Id.Id; if (id == Guid.Empty) { id = Guid.NewGuid(); } TaxonomyFieldCreationInformation fieldCI = new TaxonomyFieldCreationInformation() { Id = id, InternalName = InternalName, DisplayName = DisplayName, Group = Group, TaxonomyItem = taxItem, MultiValue = MultiValue, Required = Required, AddToDefaultView = AddToDefaultView }; if (List != null) { var list = List.GetList(SelectedWeb); field = list.CreateTaxonomyField(fieldCI); } else { field = SelectedWeb.CreateTaxonomyField(fieldCI); } WriteObject(field); }