Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileVersion] Get-PnPSite change for VersionPolicy #3470

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions documentation/Get-PnPSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Get-PnPSite -Includes RootWeb,ServerRelativeUrl

Gets the current site specifying to include RootWeb and ServerRelativeUrl properties. For the full list of properties see https://learn.microsoft.com/previous-versions/office/sharepoint-server/ee538579(v%3doffice.15)

### EXAMPLE 3
```powershell
Get-PnPSite -GetVersionPolicy
```
Get site level version policy settings.

## PARAMETERS

### -Connection
Expand All @@ -54,6 +60,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -GetVersionPolicy
Get site level version policy settings.

```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
60 changes: 57 additions & 3 deletions src/Commands/Site/GetSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,67 @@ namespace PnP.PowerShell.Commands.Site
[OutputType(typeof(Microsoft.SharePoint.Client.Site))]
public class GetSite : PnPRetrievalsCmdlet<Microsoft.SharePoint.Client.Site>
{
[Parameter(Mandatory = false)]
public SwitchParameter GetVersionPolicy;

protected override void ExecuteCmdlet()
{
DefaultRetrievalExpressions = new Expression<Func<Microsoft.SharePoint.Client.Site, object>>[] { s => s.Url, s => s.CompatibilityLevel };
var site = ClientContext.Site;
ClientContext.Load(site, RetrievalExpressions);
ClientContext.ExecuteQueryRetry();
WriteObject(site);

if (ParameterSpecified(nameof(GetVersionPolicy)))
{
site.EnsureProperties(s => s.Url, s => s.VersionPolicyForNewLibrariesTemplate, s => s.VersionPolicyForNewLibrariesTemplate.VersionPolicies);

var vp = new VersionPolicy();
vp.Url = site.Url;

if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.ServerObjectIsNull == true)
{
vp.Description = "No Site Level Policy Set";
}
else
{
site.EnsureProperties(s => s.VersionPolicyForNewLibrariesTemplate, s => s.VersionPolicyForNewLibrariesTemplate.MajorVersionLimit, s => s.VersionPolicyForNewLibrariesTemplate.VersionPolicies);

vp.DefaultTrimMode = site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode.ToString();

if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.AutoExpiration)
{
vp.Description = "Site has Automatic Policy Set";
}
else
{
if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.ExpireAfter)
{
vp.DefaultExpireAfterDays = site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultExpireAfterDays.ToString();
vp.Description = "Site has Manual settings with specific count and time limits";
}
else if (site.VersionPolicyForNewLibrariesTemplate.VersionPolicies.DefaultTrimMode == VersionPolicyTrimMode.NoExpiration)
{
vp.Description = "Site has Manual settings with specific version count limit and no time limits";
}
vp.MajorVersionLimit = site.VersionPolicyForNewLibrariesTemplate.MajorVersionLimit.ToString();
}
}

WriteObject(vp);
}
else
{
ClientContext.Load(site, RetrievalExpressions);
ClientContext.ExecuteQueryRetry();
WriteObject(site);
}
}
}

public class VersionPolicy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put it in its own .cs file under src\Commands\Model\SharePoint instead and add some code comments as to what the class does and each of the properties stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @KoenZomers for the suggestion! Should I create a new command for my VersionPolicy? Because I saw "[Cmdlet(VerbsCommon.Get, "PnPSiteSensitivityLabel")]" command also get properties from site, it uses a separate command, but not the Get-PnPSite.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. Ideally one cmdlet always return the same type so we can add this at the top:

[OutputType(typeof(Microsoft.SharePoint.Client.Site))]

If it returns anything else, it should have its own cmdlet. Please remember to also write the documentation .md files if you create a new cmdlet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @KoenZomers for the confirmation! Created a new cmdlet, added md file, reverted the changes in Get-PnPSite command and md files. Also updated the test results in the PR description. Could you please review again? Thanks so much!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KoenZomers , Could you please check the PR again? Thanks a lot!

{
public string Url { get; set; }
public string DefaultTrimMode { get; set; }
public string DefaultExpireAfterDays { get; set; }
public string MajorVersionLimit { get; set; }
public string Description { get; set; }
}
}