Ejemplo n.º 1
0
        protected override void ExecuteCmdlet()
        {
            Field field = Field.Field;

            if (field == null)
            {
                if (Field.Id != Guid.Empty)
                {
                    field = CurrentWeb.Fields.GetById(Field.Id);
                }
                else if (!string.IsNullOrEmpty(Field.Name))
                {
                    field = CurrentWeb.Fields.GetByInternalNameOrTitle(Field.Name);
                }
                ClientContext.Load(field);
                ClientContext.ExecuteQueryRetry();
            }
            if (field == null)
            {
                throw new PSArgumentException("Field not found", nameof(Field));
            }
            var ct = ContentType.GetContentTypeOrWarn(this, CurrentWeb);

            if (ct != null)
            {
                CurrentWeb.AddFieldToContentType(ct, field, Required, Hidden, true, true, false);
            }
        }