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 is null)
            {
                throw new PSArgumentException("Field not found", nameof(Field));
            }
            var ct = ContentType.GetContentTypeOrThrow(nameof(ContentType), CurrentWeb, true);

            ct.EnsureProperty(c => c.FieldLinks);
            var fieldLink = ct.FieldLinks.FirstOrDefault(f => f.Id == field.Id);

            if (fieldLink is null)
            {
                throw new PSArgumentException("Cannot find field reference in content type");
            }
            fieldLink.DeleteObject();
            ct.Update(!DoNotUpdateChildren);
            ClientContext.ExecuteQueryRetry();
        }
示例#2
0
        protected override void ExecuteCmdlet()
        {
            var list = List.GetListOrThrow(nameof(List), CurrentWeb, l => l.RootFolder, l => l.ContentTypes);

            var listContentType = ContentType.GetContentType(list);

            if (listContentType is null)
            {
                var siteContentType = ContentType.GetContentTypeOrThrow(nameof(ContentType), CurrentWeb);
                listContentType = new ContentTypePipeBind(siteContentType.Name).GetContentTypeOrThrow(nameof(ContentType), list);
            }

            listContentType.EnsureProperty(ct => ct.StringId);

            if (!listContentType.StringId.StartsWith("0x0120D520"))
            {
                throw new PSArgumentException($"Content type '{ContentType}' does not inherit from the base Document Set content type. Document Set content type IDs start with 0x120D520");
            }

            // Create the document set
            var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, listContentType.Id);

            ClientContext.ExecuteQueryRetry();

            WriteObject(result.Value);
        }
        protected override void ExecuteCmdlet()
        {
            var ct = Identity?.GetContentTypeOrThrow(nameof(Identity), CurrentWeb);

            if (Force || ShouldContinue($"Remove Content Type '{ct.EnsureProperty(c => c.Name)}'?", Resources.Confirm))
            {
                ct.DeleteObject();
                ClientContext.ExecuteQueryRetry();
            }
        }