diff --git a/documentation/Add-PnPDocumentSet.md b/documentation/Add-PnPDocumentSet.md index ae5386e44..bfff63f99 100644 --- a/documentation/Add-PnPDocumentSet.md +++ b/documentation/Add-PnPDocumentSet.md @@ -15,7 +15,7 @@ Creates a new document set in a library. ## SYNTAX ```powershell -Add-PnPDocumentSet -List -Name -ContentType +Add-PnPDocumentSet [-List] [-Name] [-ContentType ] [-Folder ] [-Connection ] ``` @@ -29,7 +29,12 @@ Allows to add new document set to library. Add-PnPDocumentSet -List "Documents" -ContentType "Test Document Set" -Name "Test" ``` -This will add a new document set based upon the 'Test Document Set' content type to a list called 'Documents'. The document set will be named 'Test' +### EXAMPLE 2 +```powershell +Add-PnPDocumentSet -List "Documents" -ContentType "Test Document Set" -Name "Test" -Folder "Projects/Europe" +``` + +This will add a new document set based upon the 'Test Document Set' content type to a list called 'Documents'. The document set will be named 'Test' and will be added to the 'Europe' folder which is located in the 'Projects' folder. Folders will be created if needed. ## PARAMETERS @@ -60,6 +65,20 @@ Default value: None Accept pipeline input: False Accept wildcard characters: False ``` +### -Folder + +The list relative URL of a folder. E.g. "MyFolder" for a folder located in the root of the list, or "MyFolder/SubFolder" for a folder located in the MyFolder folder which is located in the root of the list. + +```yaml +Type: String +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` ### -List The name of the list, its ID or an actual list object from where the document set needs to be added diff --git a/src/Commands/DocumentSets/AddDocumentSet.cs b/src/Commands/DocumentSets/AddDocumentSet.cs index ed173a2cc..06b4a807c 100644 --- a/src/Commands/DocumentSets/AddDocumentSet.cs +++ b/src/Commands/DocumentSets/AddDocumentSet.cs @@ -19,6 +19,9 @@ public class AddDocumentSet : PnPWebCmdlet [ValidateNotNullOrEmpty] public string Name; + [Parameter(Mandatory = false)] + public string Folder; + [Parameter(Mandatory = true)] [ValidateNotNullOrEmpty] public ContentTypePipeBind ContentType; @@ -42,8 +45,16 @@ protected override void ExecuteCmdlet() throw new PSArgumentException($"Content type '{ContentType}' does not inherit from the base Document Set content type. Document Set content type IDs start with 0x120D520"); } + var targetFolder = list.RootFolder; + + if (Folder != null) + { + // Create the folder if it doesn't exist + targetFolder = CurrentWeb.EnsureFolder(list.RootFolder, Folder); + } + // Create the document set - var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, listContentType.Id); + var result = DocumentSet.Create(ClientContext, targetFolder, Name, listContentType.Id); ClientContext.ExecuteQueryRetry(); WriteObject(result.Value);