This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
/
Copy pathGetSiteHistoricalVersionsStatus.cs
56 lines (50 loc) · 2.09 KB
/
GetSiteHistoricalVersionsStatus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#if !ONPREMISES
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Search.Administration;
using PnP.PowerShell.CmdletHelpAttributes;
namespace PnP.PowerShell.Commands.Search
{
[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 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
{
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<string, object> 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