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

Commit

Permalink
Merge pull request #2649 from NikCharlebois/ODSettings
Browse files Browse the repository at this point in the history
Added Get/Set-PnPTenantSyncClientRestriction
  • Loading branch information
erwinvanhunen authored Jun 6, 2020
2 parents ab0d7d0 + 3bd72d6 commit 56ce6b3
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [3.22.2006.0] (not yet released)

### Added
- Added `Get-PnPTenantSyncClientRestriction` and `Set-PnPTenantSyncClientRestriction` cmdlets to allow configuring tenant wide OneDrive sync restriction settings [PR #2649](https://github.com/pnp/PnP-PowerShell/pull/2649)

### Changed

### Contributors
- Nik Charlebois [NikCharlebois]

## [3.21.2005.0]

Expand Down
35 changes: 35 additions & 0 deletions Commands/Admin/GetTenantSyncClientRestriction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if !ONPREMISES
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base;
using System.Management.Automation;
using SharePointPnP.PowerShell.Commands.Model;

namespace SharePointPnP.PowerShell.Commands.Admin
{
[Cmdlet(VerbsCommon.Get, "PnPTenantSyncClientRestriction")]
[CmdletHelp(@"Returns organization-level OneDrive synchronization restriction settings",
DetailedDescription = @"Returns organization-level OneDrive synchronization restriction properties such as BlockMacSync,
OptOutOfGrooveBlock, and TenantRestrictionEnabled.
Currently, there are no parameters for this cmdlet.
You must have the SharePoint Online admin or Global admin role to run the cmdlet.",
SupportedPlatform = CmdletSupportedPlatform.Online,
Category = CmdletHelpCategory.TenantAdmin,
OutputType = typeof(SPOTenantSyncClientRestriction))]
[CmdletExample(
Code = @"PS:> Get-PnPTenantSyncClientRestriction",
Remarks = @"This example returns all tenant OneDrive synchronization restriction settings", SortOrder = 1)]
public class GetPnPTenantSyncClientRestriction : PnPAdminCmdlet
{
protected override void ExecuteCmdlet()
{
ClientContext.Load(Tenant);
ClientContext.Load(Tenant, t => t.HideDefaultThemes);
ClientContext.ExecuteQueryRetry();
WriteObject(new SPOTenantSyncClientRestriction(Tenant));
}
}
}
#endif
93 changes: 93 additions & 0 deletions Commands/Admin/SetTenantSyncClientRestriction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#if !ONPREMISES
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using SharePointPnP.PowerShell.Commands.Base;
using System.Management.Automation;
using System;
using System.Collections.Generic;
using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources;
using SharePointPnP.PowerShell.Commands.Model;

namespace SharePointPnP.PowerShell.Commands.Admin
{
[Cmdlet(VerbsCommon.Set, "PnPTenantSyncClientRestriction", DefaultParameterSetName = ParameterAttribute.AllParameterSets)]
[CmdletHelp(@"Sets organization-level sync client restriction properties",
DetailedDescription = @"Sets organization-level sync client restriction properties such as BlockMacSync, OptOutOfGroveBlock, and DisableReportProblemDialog.
You must have the SharePoint Online admin or Global admin role to run the cmdlet.",
SupportedPlatform = CmdletSupportedPlatform.Online,
Category = CmdletHelpCategory.TenantAdmin)]
[CmdletExample(
Code = @"PS:> Set-PnPTenantSyncClientRestriction -BlockMacSync:$false",
Remarks = @"This example blocks access to Mac sync clients for OneDrive file synchronization", SortOrder = 1)]
[CmdletExample(
Code = @"PS:> Set-SPOTenantSyncClientRestriction -ExcludedFileExtensions ""pptx;docx;xlsx""",
Remarks = @"This example blocks syncing of PowerPoint, Word, and Excel file types using the new sync client (OneDrive.exe).", SortOrder = 2)]
public class SetTenantSyncClientRestriction : PnPAdminCmdlet
{
[Parameter(Mandatory = false, HelpMessage = "Block Mac sync clients-- the Beta version and the new sync client (OneDrive.exe). The values for this parameter are $true and $false. The default value is $false.")]
public SwitchParameter BlockMacSync;

[Parameter(Mandatory = false, HelpMessage = "Specifies if the Report Problem Dialog is disabled or not.")]
public SwitchParameter DisableReportProblemDialog;

[Parameter(Mandatory = false, HelpMessage = "Sets the domain GUID to add to the safe recipient list. Requires a minimum of 1 domain GUID. The maximum number of domain GUIDs allowed are 125. I.e. 634c71f6-fa83-429c-b77b-0dba3cb70b93,4fbc735f-0ac2-48ba-b035-b1ae3a480887.")]
public List<Guid> DomainGuids;

[Parameter(Mandatory = false, HelpMessage = "Enables the feature to block sync originating from domains that are not present in the safe recipients list.")]
public SwitchParameter Enable;

[Parameter(Mandatory = false, HelpMessage = @"Blocks certain file types from syncing with the new sync client (OneDrive.exe). Provide as one string separating the extensions using a semicolon (;). I.e. ""docx;pptx""")]
public List<string> ExcludedFileExtensions;

[Parameter(Mandatory = false, HelpMessage = "Controls whether or not a tenant's users can sync OneDrive for Business libraries with the old OneDrive for Business sync client. The valid values are OptOut, HardOptin, and SoftOptin.")]
public Enums.GrooveBlockOption GrooveBlockOption;

protected override void ExecuteCmdlet()
{
ClientContext.Load(Tenant);
ClientContext.ExecuteQueryRetry();

if (ParameterSpecified(nameof(DomainGuids)))
{
Tenant.AllowedDomainListForSyncClient = new List<Guid>(DomainGuids);
}

Tenant.BlockMacSync = BlockMacSync.ToBool();
Tenant.IsUnmanagedSyncClientForTenantRestricted = Enable.ToBool();
Tenant.DisableReportProblemDialog = DisableReportProblemDialog.ToBool();

if (ParameterSpecified(nameof(ExcludedFileExtensions)))
{
Tenant.ExcludedFileExtensionsForSyncClient = ExcludedFileExtensions;
}

if(ParameterSpecified(nameof(GrooveBlockOption)))
{
switch (GrooveBlockOption)
{
case Enums.GrooveBlockOption.OptOut:
Tenant.OptOutOfGrooveBlock = true;
Tenant.OptOutOfGrooveSoftBlock = true;
break;

case Enums.GrooveBlockOption.HardOptin:
Tenant.OptOutOfGrooveBlock = false;
Tenant.OptOutOfGrooveSoftBlock = true;
break;

case Enums.GrooveBlockOption.SoftOptin:
Tenant.OptOutOfGrooveBlock = true;
Tenant.OptOutOfGrooveSoftBlock = false;
break;

default:
throw new PSArgumentException(string.Format(Resources.GrooveBlockOptionNotSupported, nameof(GrooveBlockOption), GrooveBlockOption), nameof(GrooveBlockOption));
}
}
ClientContext.ExecuteQueryRetry();
}
}
}
#endif
23 changes: 23 additions & 0 deletions Commands/Enums/GrooveBlockOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SharePointPnP.PowerShell.Commands.Enums
{
/// <summary>
/// Specifies the options for allowing using the old Groove sync client, used in i.e. <see cref="SetTenantSyncClientRestriction"/>.
/// </summary>
public enum GrooveBlockOption : short
{
/// <summary>
/// Allows the usage of the old Groove sync client
/// </summary>
OptOut,

/// <summary>
/// Groove sync client will be blocked and users are asked to upgrade
/// </summary>
HardOptin,

/// <summary>
/// Groove sync client is still allows but users will be asked to upgrade
/// </summary>
SoftOptin
}
}
64 changes: 64 additions & 0 deletions Commands/Model/SPOTenantSyncClientRestriction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#if !ONPREMISES
using Microsoft.Online.SharePoint.TenantAdministration;
using System;
using System.Collections.Generic;

namespace SharePointPnP.PowerShell.Commands.Model
{
/// <summary>
/// Returned properties for <see cref="GetPnPTenantSyncClientRestriction"/>
/// </summary>
public class SPOTenantSyncClientRestriction
{
/// <summary>
/// Indication if Mac sync clients, the Beta version and the new sync client (OneDrive.exe), should be blocked
/// </summary>
public bool BlockMacSync { get; private set; }

/// <summary>
/// The domain GUID to add to the safe recipient list. Requires a minimum of 1 domain GUID to be enabled. The maximum number of domain GUIDs allowed are 125.
/// </summary>
public List<Guid> AllowedDomainList { get; private set; }

/// <summary>
/// Blocks certain file types from syncing with the new sync client (OneDrive.exe)
/// </summary>
public List<string> ExcludedFileExtensions { get; private set; }

/// <summary>
/// Indicates if the usage of the old Groove sync client is allowed (true) or not (false)
/// </summary>
public bool OptOutOfGrooveBlock { get; private set; }

/// <summary>
/// Indicates if the user is asked to upgrade to the new Groove client, but can still use the old client (true) of if the user is forced to upgrade (false)
/// </summary>
public bool OptOutOfGrooveSoftBlock { get; private set; }

/// <summary>
/// Specifies if the Report Problem Dialog is disabled or not
/// </summary>
public bool DisableReportProblemDialog { get; private set; }

/// <summary>
/// Indicates if a sync restriction is set on the tenant
/// </summary>
public bool TenantRestrictionEnabled { get; private set; }

/// <summary>
/// Instantiates a new SPOTenantSyncClientRestriction instance
/// </summary>
/// <param name="tenant">Tenant instance to get the properties from to fill this instance</param>
public SPOTenantSyncClientRestriction(Tenant tenant)
{
AllowedDomainList = new List<Guid>(tenant.AllowedDomainListForSyncClient);
BlockMacSync = tenant.BlockMacSync;
ExcludedFileExtensions = new List<string>(tenant.ExcludedFileExtensionsForSyncClient);
OptOutOfGrooveBlock = tenant.OptOutOfGrooveBlock;
OptOutOfGrooveSoftBlock = tenant.OptOutOfGrooveSoftBlock;
DisableReportProblemDialog = tenant.DisableReportProblemDialog;
TenantRestrictionEnabled = tenant.IsUnmanagedSyncClientForTenantRestricted;
}
}
}
#endif
9 changes: 9 additions & 0 deletions Commands/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Commands/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@
<data name="SetRequestAccessEmailsOnlyOneAddressAllowed" xml:space="preserve">
<value>Only one e-mail address can be configured to receive the access requests</value>
</data>
<data name="GrooveBlockOptionNotSupported" xml:space="preserve">
<value>The provided option for {0} being {1} is not yet supported in this cmdlet</value>
</data>
</root>
4 changes: 4 additions & 0 deletions Commands/SharePointPnP.PowerShell.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
<Compile Include="Admin\AddTenantTheme.cs" />
<Compile Include="Admin\ClearTenantAppCatalogUrl.cs" />
<Compile Include="Admin\GetKnowledgeHubSite.cs" />
<Compile Include="Admin\GetTenantSyncClientRestriction.cs" />
<Compile Include="Admin\RemoveKnowledgeHubSite.cs" />
<Compile Include="Admin\SetKnowledgeHubSite.cs" />
<Compile Include="Admin\RevokeHubSiteRights.cs" />
Expand All @@ -569,6 +570,7 @@
<Compile Include="Admin\GetHubSiteChild.cs" />
<Compile Include="Admin\GetTenantId.cs" />
<Compile Include="Admin\RegisterAppCatalogSite.cs" />
<Compile Include="Admin\SetTenantSyncClientRestriction.cs" />
<Compile Include="Base\BasePSCmdlet.cs" />
<Compile Include="Apps\AddApplicationCustomizer.cs" />
<Compile Include="Apps\GetApplicationCustomizer.cs" />
Expand Down Expand Up @@ -649,6 +651,7 @@
<Compile Include="ClientSidePages\SaveClientSidePageConversionLog.cs" />
<Compile Include="Enums\AlertFilter.cs" />
<Compile Include="Enums\AuditContentType.cs" />
<Compile Include="Enums\GrooveBlockOption.cs" />
<Compile Include="Enums\HttpRequestMethod.cs" />
<Compile Include="Enums\InitializationType.cs" />
<Compile Include="Enums\ListItemUpdateType.cs" />
Expand All @@ -674,6 +677,7 @@
<Compile Include="Model\ProvisionedSite.cs" />
<Compile Include="Model\ServicePrincipalPermissionGrant.cs" />
<Compile Include="ClientSidePages\ConvertToClientSidePage.cs" />
<Compile Include="Model\SPOTenantSyncClientRestriction.cs" />
<Compile Include="Navigation\GetNavigationNode.cs" />
<Compile Include="Branding\SetWebTheme.cs" />
<Compile Include="ClientSidePages\GetClientSideComponent.cs" />
Expand Down

0 comments on commit 56ce6b3

Please sign in to comment.