From 6c266dc7a1d2e4a775a7e2c6375c36675696524c Mon Sep 17 00:00:00 2001 From: Zhuo Wei Li Date: Fri, 31 Jul 2020 09:00:52 -0700 Subject: [PATCH 1/3] Added command for getting the historical versions status of a site --- CHANGELOG.md | 2 + .../Search/GetSiteHistoricalVersionsStatus.cs | 56 +++++++++++++++++++ .../SharePointPnP.PowerShell.Commands.csproj | 1 + 3 files changed, 59 insertions(+) create mode 100644 Commands/Search/GetSiteHistoricalVersionsStatus.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index d63056620..19a7a1489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [3.23.2007.0] (not yet released) ### Added +- Added Get-PnPSiteHistoricalVersionsStatus ### Changed - Fixed issue where using `Disconnect-PnPOnline -Connection $variable` after having connected using `$variable = Connect-PnPOnline -CertificatePath -ReturnConnection`, it would not clean up the certificate on that connection instance passed in by $variable, but instead try to do it on the current connection context [PR #2755](https://github.com/pnp/PnP-PowerShell/pull/2755) @@ -15,6 +16,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors - Gautam Sheth [gautamdsheth] - Koen Zomers [koenzomers] +- Zhuo Wei Li [ZhuoWeiLi] ## [3.22.2006.2] diff --git a/Commands/Search/GetSiteHistoricalVersionsStatus.cs b/Commands/Search/GetSiteHistoricalVersionsStatus.cs new file mode 100644 index 000000000..fadae864b --- /dev/null +++ b/Commands/Search/GetSiteHistoricalVersionsStatus.cs @@ -0,0 +1,56 @@ +#if !ONPREMISES +using System.Collections.Generic; +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client.Search.Administration; +using SharePointPnP.PowerShell.CmdletHelpAttributes; + +namespace SharePointPnP.PowerShell.Commands.Search +{ + [Cmdlet(VerbsCommon.Get, "PnPSiteHistoricalVersionsStatus", DefaultParameterSetName = "Xml")] + [CmdletHelp("Returns information about the Historical Versions feature for the current site collection from the context. " + + "The document statistics are only updated periodically, check the next update time property (in UTC) to see when new data will be available.", + SupportedPlatform = CmdletSupportedPlatform.Online, + Category = CmdletHelpCategory.Search)] + [CmdletExample( + Code = @"PS:> Get-PnPSiteHistoricalVersionsStatus", + Remarks = "Returns the status of the feature as well as the number of documents processed for the site if the feature is enabled.", + SortOrder = 1)] + public class GetSiteHistoricalVersionsStatus : PnPWebCmdlet + { + + protected override void ExecuteCmdlet() + { + var siteLog = new SiteCrawlLog(ClientContext, ClientContext.Site); + ClientContext.Load(siteLog); + + var resultTable = siteLog.GetHistoricalVersionsStatus(); + ClientContext.ExecuteQueryRetry(); + + if (resultTable.Value == null || resultTable.Value.Rows.Count == 0) + { + WriteWarning("No information was obtained for the current site"); + } + else + { + // The API should only return 1 row + WriteObject(ConvertToPSObject(resultTable.Value.Rows[0])); + } + + } + + private object ConvertToPSObject(IDictionary r) + { + PSObject res = new PSObject(); + if (r != null) + { + foreach (var kvp in r) + { + res.Properties.Add(new PSNoteProperty(kvp.Key, kvp.Value)); + } + } + return res; + } + } +} +#endif diff --git a/Commands/SharePointPnP.PowerShell.Commands.csproj b/Commands/SharePointPnP.PowerShell.Commands.csproj index ed7d2865d..796122a2a 100644 --- a/Commands/SharePointPnP.PowerShell.Commands.csproj +++ b/Commands/SharePointPnP.PowerShell.Commands.csproj @@ -750,6 +750,7 @@ + From 01996fb5e75d817c8a74219606e2d2bebcd193f7 Mon Sep 17 00:00:00 2001 From: Zhuo Wei Li Date: Wed, 5 Aug 2020 11:10:02 -0700 Subject: [PATCH 2/3] Fixed namespace --- Commands/Search/GetSiteHistoricalVersionsStatus.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Commands/Search/GetSiteHistoricalVersionsStatus.cs b/Commands/Search/GetSiteHistoricalVersionsStatus.cs index fadae864b..87f2311e9 100644 --- a/Commands/Search/GetSiteHistoricalVersionsStatus.cs +++ b/Commands/Search/GetSiteHistoricalVersionsStatus.cs @@ -3,9 +3,9 @@ using System.Management.Automation; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Search.Administration; -using SharePointPnP.PowerShell.CmdletHelpAttributes; +using PnP.PowerShell.CmdletHelpAttributes; -namespace SharePointPnP.PowerShell.Commands.Search +namespace PnP.PowerShell.Commands.Search { [Cmdlet(VerbsCommon.Get, "PnPSiteHistoricalVersionsStatus", DefaultParameterSetName = "Xml")] [CmdletHelp("Returns information about the Historical Versions feature for the current site collection from the context. " + From 534b490111299d3197a4ffab745c0775bbe9e806 Mon Sep 17 00:00:00 2001 From: Zhuo Wei Li Date: Fri, 7 Aug 2020 12:42:08 -0700 Subject: [PATCH 3/3] Updated documentation to be more descriptive about historical versions --- CHANGELOG.md | 2 +- Commands/Search/GetSiteHistoricalVersionsStatus.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d2092838..a7abc1c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Updated `Get/Set-PnPSearchSettings` with an option `-SearchBoxPlaceholderText` to set search placeholder text for the SPO nav bar search box - Added Set-PnPTermGroup cmdlet to update an existing taxonomy term group. - Added Set-PnPTeamifyPromptHidden to hide the teamify prompt on a group connected Team Site (modern team site) -- Added Get-PnPSiteHistoricalVersionsStatus to get information about the Historical Versions feature related to Search +- Added Get-PnPSiteHistoricalVersionsStatus to get information about the Historical Versions feature, a feature that makes past versions of documents searchable for eDiscovery when enabled ### Changed - Changed the client id of the application used behind the scenes when authenticating to a tenant where Legacy Authentication has been turned off. We now by default utilize the PnP Management Shell application. If you have not provided consent you will be prompted with a message on how to provide consent. diff --git a/Commands/Search/GetSiteHistoricalVersionsStatus.cs b/Commands/Search/GetSiteHistoricalVersionsStatus.cs index 87f2311e9..746bdf1f8 100644 --- a/Commands/Search/GetSiteHistoricalVersionsStatus.cs +++ b/Commands/Search/GetSiteHistoricalVersionsStatus.cs @@ -7,14 +7,14 @@ namespace PnP.PowerShell.Commands.Search { - [Cmdlet(VerbsCommon.Get, "PnPSiteHistoricalVersionsStatus", DefaultParameterSetName = "Xml")] - [CmdletHelp("Returns information about the Historical Versions feature for the current site collection from the context. " + - "The document statistics are only updated periodically, check the next update time property (in UTC) to see when new data will be available.", + [Cmdlet(VerbsCommon.Get, "PnPSiteHistoricalVersionsStatus")] + [CmdletHelp("Returns summary crawl info about the Historical Versions feature for the current site collection from the context. " + + "This is a feature that makes past versions of documents searchable for eDiscovery when enabled.", SupportedPlatform = CmdletSupportedPlatform.Online, Category = CmdletHelpCategory.Search)] [CmdletExample( Code = @"PS:> Get-PnPSiteHistoricalVersionsStatus", - Remarks = "Returns the status of the feature as well as the number of documents processed for the site if the feature is enabled.", + Remarks = "Returns the count of documents with historical versions processed and the count of total documents with versions enabled on the site, as well as when these counts will be next updated (all times in UTC).", SortOrder = 1)] public class GetSiteHistoricalVersionsStatus : PnPWebCmdlet {