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); }