Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit ad73b0b

Browse files
committed
Merge branch 'dev' into feature/Add-PnPFile(s)ToProvisioningTemplate-ExtractWebPart
2 parents 3960415 + 02ee1b3 commit ad73b0b

18 files changed

+233
-49
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
77

8-
## [2.29.1808.0] unreleased
8+
## [3.0.1808.0]
99
### Added
10+
- Added Get-PnPLabel and Set-PnPLabel to get and set compliancy tags/labels on a list or library. Only available for SharePoint Online.
1011

1112
### Changed
12-
13-
### Deprecated
13+
- Fixed Get-PnPSearchCrawlLog where listing user profile crawl entries failed for some tenants
14+
- Added default pipebind to Get-PnPListitem
15+
- Add-PnPDocumentSet now adds the content type to the document library.
16+
- Updated documentation for Clear-PnPRecycleBinItem and Restore-PnPRecycleBinItem
17+
- Updated documentation for New-PnPSite
1418

1519
### Contributors
20+
- KoenZomers
21+
- robinmeure
1622

1723
## [2.28.1807.0]
1824
### Changed

Commands/Admin/NewSite.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ namespace SharePointPnP.PowerShell.Commands
4040
Remarks = @"This will create a new Communications Site collection with the title 'Contoso' and the url 'https://tenant.sharepoint.com/sites/contoso'. File sharing for guest users will be enabled.",
4141
SortOrder = 5)]
4242
[CmdletExample(
43-
Code = @"PS:> New-PnPSite -Type TeamSite -Title Contoso -Alias contoso",
44-
Remarks = @"This will create a new Modern Team Site collection with the title 'Contoso' and the url 'https://tenant.sharepoint.com/sites/contoso'.",
43+
Code = @"PS:> New-PnPSite -Type TeamSite -Title 'Team Contoso' -Alias contoso",
44+
Remarks = @"This will create a new Modern Team Site collection with the title 'Team Contoso' and the url 'https://tenant.sharepoint.com/sites/contoso' or 'https://tenant.sharepoint.com/teams/contoso' based on the managed path configuration in the SharePoint Online Admin portal.",
4545
SortOrder = 6)]
4646
[CmdletExample(
47-
Code = @"PS:> New-PnPSite -Type TeamSite -Title Contoso -Alias contoso -IsPublic",
48-
Remarks = @"This will create a new Modern Team Site collection with the title 'Contoso' and the url 'https://tenant.sharepoint.com/sites/contoso' and sets the site to public.",
47+
Code = @"PS:> New-PnPSite -Type TeamSite -Title 'Team Contoso' -Alias contoso -IsPublic",
48+
Remarks = @"This will create a new Modern Team Site collection with the title 'Team Contoso' and the url 'https://tenant.sharepoint.com/sites/contoso' or 'https://tenant.sharepoint.com/teams/contoso' based on the managed path configuration in the SharePoint Online Admin portal and sets the site to public.",
4949
SortOrder = 7)]
5050
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Title", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection", ParameterSetName = ParameterSet_COMMUNICATIONBUILTINDESIGN)]
5151
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Title", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection", ParameterSetName = ParameterSet_COMMUNICATIONCUSTOMDESIGN)]
@@ -62,7 +62,7 @@ namespace SharePointPnP.PowerShell.Commands
6262
[CmdletAdditionalParameter(ParameterType = typeof(uint), ParameterName = "Lcid", Mandatory = false, HelpMessage = @"Specifies the language of the new site collection. Defaults to the current language of the web connected to.", ParameterSetName = ParameterSet_COMMUNICATIONBUILTINDESIGN)]
6363
[CmdletAdditionalParameter(ParameterType = typeof(uint), ParameterName = "Lcid", Mandatory = false, HelpMessage = @"Specifies the language of the new site collection. Defaults to the current language of the web connected to.", ParameterSetName = ParameterSet_COMMUNICATIONCUSTOMDESIGN)]
6464
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Title", Mandatory = true, HelpMessage = @"Specifies the title of the new site collection", ParameterSetName = ParameterSet_TEAM)]
65-
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Alias", Mandatory = true, HelpMessage = @"Specifies the alias of the new site collection", ParameterSetName = ParameterSet_TEAM)]
65+
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Alias", Mandatory = true, HelpMessage = @"Specifies the alias of the new site collection which represents the part of the URL that will be assigned to the site behind 'https://tenant.sharepoint.com/sites/' or 'https://tenant.sharepoint.com/teams/' based on the managed path configuration in the SharePoint Online Admin portal", ParameterSetName = ParameterSet_TEAM)]
6666
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Description", Mandatory = false, HelpMessage = @"Specifies the description of the new site collection", ParameterSetName = ParameterSet_TEAM)]
6767
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "Classification", Mandatory = false, HelpMessage = @"Specifies the classification of the new site collection", ParameterSetName = ParameterSet_TEAM)]
6868
[CmdletAdditionalParameter(ParameterType = typeof(string), ParameterName = "IsPublic", Mandatory = false, HelpMessage = @"Specifies if new site collection is public. Defaults to false.", ParameterSetName = ParameterSet_TEAM)]

Commands/Admin/UnregisterHubSite.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ protected override void ExecuteCmdlet()
2828
var hubSitesProperties = Tenant.GetHubSitesProperties();
2929
ClientContext.Load(hubSitesProperties);
3030
ClientContext.ExecuteQueryRetry();
31-
var hubSite = hubSitesProperties.Single(h => h.SiteUrl.Equals(Site.Url, StringComparison.OrdinalIgnoreCase));
32-
33-
Tenant.UnregisterHubSiteById(hubSite.ID);
31+
HubSiteProperties props = null;
32+
if (Site.Id != Guid.Empty)
33+
{
34+
props = hubSitesProperties.Single(h => h.SiteId == Site.Id);
35+
}
36+
else
37+
{
38+
props = hubSitesProperties.Single(h => h.SiteUrl.Equals(Site.Url, StringComparison.OrdinalIgnoreCase));
39+
}
40+
Tenant.UnregisterHubSiteById(props.ID);
3441
ClientContext.ExecuteQueryRetry();
3542
}
3643
}

Commands/Base/ConnectOnline.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,7 @@ protected override void ProcessRecord()
552552
}
553553
else if (ParameterSetName == ParameterSet_ACCESSTOKEN)
554554
{
555-
#if !NETSTANDARD2_0
556-
var jwtToken = new System.IdentityModel.Tokens.JwtSecurityToken(AccessToken);
557-
#else
558555
var jwtToken = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(AccessToken);
559-
#endif
560556
var aud = jwtToken.Audiences.FirstOrDefault();
561557
if (aud != null)
562558
{

Commands/Base/GetAccessToken.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IdentityModel.Tokens.Jwt;
66
#else
77
using System.IdentityModel.Tokens;
8+
using System.IdentityModel.Tokens.Jwt;
89
#endif
910
using System.Linq;
1011
using System.Management.Automation;

Commands/Base/PipeBinds/SitePipeBind.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,40 @@ public SitePipeBind(string url)
2020
{
2121
if (string.IsNullOrEmpty(url))
2222
{
23-
throw new ArgumentException("Url");
23+
throw new ArgumentException("Site");
2424
}
25-
Uri uri;
26-
try
25+
if (Guid.TryParse(url, out Guid siteId))
2726
{
28-
uri = new Uri(url);
27+
_id = siteId;
2928
}
30-
catch (UriFormatException)
29+
else
3130
{
32-
throw new ArgumentException("Url");
31+
Uri uri;
32+
try
33+
{
34+
uri = new Uri(url);
35+
}
36+
catch (UriFormatException)
37+
{
38+
throw new ArgumentException("Site");
39+
}
40+
_url = url;
3341
}
34-
_url = url;
3542
}
3643

3744
public SitePipeBind(Microsoft.SharePoint.Client.Site site)
3845
{
39-
site.EnsureProperties(s => s.Url);
46+
site.EnsureProperties(s => s.Url, s => s.Id);
4047
_url = site.Url;
4148
_site = site;
49+
_id = site.Id;
4250
}
4351

4452
public string Url => _url;
4553

4654
public Microsoft.SharePoint.Client.Site Site => _site;
47-
55+
56+
public Guid Id => _id;
57+
4858
}
4959
}

Commands/Base/SPOnlineConnectionHelper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ internal static SPOnlineConnection InstantiateDeviceLoginConnection(string url,
180180

181181
internal static SPOnlineConnection InstantiateGraphAccessTokenConnection(string accessToken, PSHost host, bool disableTelemetry)
182182
{
183-
#if NETSTANDARD2_0
184183
var jwtToken = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(accessToken);
185-
#else
186-
var jwtToken = new System.IdentityModel.Tokens.JwtSecurityToken(accessToken);
187-
#endif
188184
var tokenResult = new TokenResult();
189185
tokenResult.AccessToken = accessToken;
190186
tokenResult.ExpiresOn = jwtToken.ValidTo;

Commands/DocumentSets/AddDocumentSet.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
using Microsoft.SharePoint.Client.DocumentSet;
44
using SharePointPnP.PowerShell.CmdletHelpAttributes;
55
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
6+
using System.Linq;
67

78
namespace SharePointPnP.PowerShell.Commands.DocumentSets
89
{
910
[Cmdlet(VerbsCommon.Add, "PnPDocumentSet")]
1011
[CmdletHelp("Creates a new document set in a library.",
1112
Category = CmdletHelpCategory.DocumentSets,
12-
OutputType=typeof(string))]
13+
OutputType = typeof(string))]
1314
[CmdletExample(
1415
Code = @"PS:> Add-PnPDocumentSet -List ""Documents"" -ContentType ""Test Document Set"" -Name ""Test""",
1516
Remarks = "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'",
@@ -19,21 +20,44 @@ public class AddDocumentSet : PnPWebCmdlet
1920
[Parameter(Mandatory = true, HelpMessage = "The name of the list, its ID or an actual list object from where the document set needs to be added")]
2021
public ListPipeBind List;
2122

22-
[Parameter(Mandatory = true, HelpMessage = "The name of the document set")]
23+
[Parameter(Mandatory = true, HelpMessage = "The name of the document set")]
2324
public string Name;
2425

25-
[Parameter(Mandatory = true, HelpMessage = "The name of the content type, its ID or an actual content object referencing to the document set.")]
26+
[Parameter(Mandatory = true, HelpMessage = "The name of the content type, its ID or an actual content object referencing to the document set")]
2627
public ContentTypePipeBind ContentType;
28+
2729
protected override void ExecuteCmdlet()
2830
{
2931
var list = List.GetList(SelectedWeb);
30-
list.EnsureProperty(l => l.RootFolder);
32+
list.EnsureProperties(l => l.RootFolder, l => l.ContentTypes);
33+
34+
// Try getting the content type from the Web
35+
var contentType = ContentType.GetContentType(SelectedWeb);
36+
37+
// If content type could not be found but a content type ID has been passed in, try looking for the content type ID on the list instead
38+
if (contentType == null && !string.IsNullOrEmpty(ContentType.Id))
39+
{
40+
contentType = list.ContentTypes.FirstOrDefault(ct => ct.StringId.Equals(ContentType.Id));
41+
}
42+
else
43+
{
44+
// Content type has been found on the web, check if it also exists on the list
45+
if (list.ContentTypes.All(ct => !ct.StringId.Equals(contentType.Id.StringValue, System.StringComparison.InvariantCultureIgnoreCase)))
46+
{
47+
contentType = list.ContentTypes.FirstOrDefault(ct => ct.Name.Equals(ContentType.Name));
48+
}
49+
}
3150

32-
var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, ContentType.GetContentType(SelectedWeb).Id);
51+
if (contentType == null)
52+
{
53+
throw new PSArgumentException("The provided contenttype has not been found", "ContentType");
54+
}
3355

56+
// Create the document set
57+
var result = DocumentSet.Create(ClientContext, list.RootFolder, Name, contentType.Id);
3458
ClientContext.ExecuteQueryRetry();
3559

3660
WriteObject(result.Value);
3761
}
3862
}
39-
}
63+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#if !ONPREMISES
2+
using System.Management.Automation;
3+
using Microsoft.SharePoint.Client;
4+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
5+
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
6+
7+
namespace SharePointPnP.PowerShell.Commands.InformationManagement
8+
{
9+
[Cmdlet(VerbsCommon.Get, "PnPLabel")]
10+
[CmdletHelp("Gets the label/tag of the specfied list or library (if applicable)", Category = CmdletHelpCategory.InformationManagement, SupportedPlatform = CmdletSupportedPlatform.Online)]
11+
[CmdletExample(
12+
Code = @"PS:> Get-PnPLabel -List ""Demo List""",
13+
Remarks = @"This gets the label which is set to a list or a library.", SortOrder = 1)]
14+
15+
public class GetListComplianceTag : PnPWebCmdlet
16+
{
17+
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID or Url of the list.")]
18+
public ListPipeBind List;
19+
20+
protected override void ExecuteCmdlet()
21+
{
22+
var list = List.GetList(SelectedWeb);
23+
if (list != null)
24+
{
25+
var listUrl = list.RootFolder.ServerRelativeUrl;
26+
var label = Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.GetListComplianceTag(ClientContext, listUrl);
27+
ClientContext.ExecuteQueryRetry();
28+
29+
if (label.Value == null)
30+
{
31+
WriteWarning("No label found for the specified library.");
32+
}
33+
else
34+
{
35+
WriteObject("The label '" + label.Value.TagName + "' is set to the specified list or library. ");
36+
// There is no property yet that exposes if the SyncToItems is set or not.. :(
37+
WriteObject("Block deletion: " + label.Value.BlockDelete.ToString());
38+
WriteObject("Block editing: " + label.Value.BlockEdit.ToString());
39+
}
40+
}
41+
else
42+
{
43+
WriteWarning("List or library not found.");
44+
}
45+
}
46+
}
47+
}
48+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#if !ONPREMISES
2+
using System.Management.Automation;
3+
using Microsoft.SharePoint.Client;
4+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
5+
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
6+
7+
namespace SharePointPnP.PowerShell.Commands.InformationManagement
8+
{
9+
[Cmdlet(VerbsCommon.Set, "PnPLabel")]
10+
[CmdletHelp("Sets a label/tag on the specified list or library", Category = CmdletHelpCategory.InformationManagement, SupportedPlatform = CmdletSupportedPlatform.Online)]
11+
[CmdletExample(
12+
Code = @"PS:> Set-PnPLabel -List ""Demo List"" -Label ""Project Documentation""",
13+
Remarks = @"This sets an O365 label on the specified list or library. ", SortOrder = 1)]
14+
[CmdletExample(
15+
Code = @"PS:> Set-PnPLabel -List ""Demo List"" -Label ""Project Documentation"" -SyncToItems $true",
16+
Remarks = @"This sets an O365 label on the specified list or library and sets the label to all the items in the list and library as well.", SortOrder = 2)]
17+
18+
[CmdletExample(
19+
Code = @"PS:> Set-PnPLabel -List ""Demo List"" -Label ""Project Documentation"" -BlockDelete $true -BlockEdit $true",
20+
Remarks = @"This sets an O365 label on the specified list or library. Next, it also blocks the ability to either edit or delete the item. ", SortOrder = 3)]
21+
public class SetListComplianceTag : PnPWebCmdlet
22+
{
23+
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The ID or Url of the list.")]
24+
public ListPipeBind List;
25+
26+
[Parameter(Mandatory = true, HelpMessage = "The name of the label.")]
27+
public string Label;
28+
29+
[Parameter(Mandatory = false, HelpMessage = "Apply label to existing items in the library.")]
30+
public bool SyncToItems;
31+
32+
[Parameter(Mandatory = false, HelpMessage = "Block deletion of items in the library.")]
33+
public bool BlockDeletion;
34+
35+
[Parameter(Mandatory = false, HelpMessage = "Block edititing of items in the library.")]
36+
public bool BlockEdit;
37+
38+
protected override void ExecuteCmdlet()
39+
{
40+
var list = List.GetList(SelectedWeb);
41+
if (list != null)
42+
{
43+
var listUrl = list.RootFolder.ServerRelativeUrl;
44+
Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.SetListComplianceTag(ClientContext, listUrl, Label, SyncToItems, BlockEdit, BlockDeletion);
45+
46+
try
47+
{
48+
ClientContext.ExecuteQueryRetry();
49+
}
50+
catch (System.Exception error)
51+
{
52+
WriteWarning(error.Message.ToString());
53+
}
54+
55+
}
56+
else
57+
{
58+
WriteWarning("List or library not found.");
59+
60+
}
61+
}
62+
}
63+
}
64+
#endif

0 commit comments

Comments
 (0)