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

Feature #661 - Sharing Capability for New-PnPTenantSite #1994

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-ExemptFromBlockDownloadOfNonViewableFiles` parameter to `Set-PnPList` cmdlet to configure access capabilites for unmanaged devices at list level. [#1973](https://github.com/pnp/powershell/pull/1973)
- Added `-PercentComplete`, `-Priority`, `-StartDateTime`, `-DueDateTime` and `-Description` to `Add-PnPPlannerTask` [#1964](https://github.com/pnp/powershell/pull/1964)
- Added `Set-PnPContentType` cmdlet to update the properties of the Content Types in a list or a web. [#1981](https://github.com/pnp/powershell/pull/1981)
- Added `-SharingCapability` parameter to the `New-PnPTenantSite` cmdlet to update the Sharing capabilties of the newly provisioned classic site collection. [#1994](https://github.com/pnp/powershell/pull/1994)
- Added optional `-IncludeAllLists` to `Get-PnPSiteScriptFromWeb` which will include the JSON definition of all custom lists of the current site in the output [#1987](https://github.com/pnp/powershell/pull/1987)
- Added `-UpdateChildren` parameter to `Add-PnPFieldToContentType` cmdlet. This allows users to skip pushing the fields to child content types. [#1092](https://github.com/pnp/powershell/pull/1992)

Expand Down
20 changes: 18 additions & 2 deletions documentation/New-PnPTenantSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Creates a new (classic) site collection for the current tenant
```powershell
New-PnPTenantSite -Title <String> -Url <String> -Owner <String> [-Lcid <UInt32>] [-Template <String>]
-TimeZone <Int32> [-ResourceQuota <Double>] [-ResourceQuotaWarningLevel <Double>] [-StorageQuota <Int64>]
[-StorageQuotaWarningLevel <Int64>] [-RemoveDeletedSite] [-Wait] [-Connection <PnPConnection>]
[-StorageQuotaWarningLevel <Int64>] [-RemoveDeletedSite] [-SharingCapability <SharingCapabilities>] [-Wait] [-Connection <PnPConnection>]
[<CommonParameters>]
```

Expand Down Expand Up @@ -216,16 +216,32 @@ Accept wildcard characters: False
```

### -Wait
Waits for the site collection to be fully provisioned.

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

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

### -SharingCapability
Specifies what the sharing capabilities are for the site. Possible values: Disabled, ExternalUserSharingOnly, ExternalUserAndGuestSharing, ExistingExternalUserSharingOnly. It will only work if Wait parameter is specified.

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

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Accepted values: Disabled, ExternalUserSharingOnly, ExternalUserAndGuestSharing, ExistingExternalUserSharingOnly
```

## RELATED LINKS
Expand Down
54 changes: 37 additions & 17 deletions src/Commands/Admin/NewTenantSite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.SharePoint.Client;
using Microsoft.Online.SharePoint.TenantManagement;
using Microsoft.SharePoint.Client;
using PnP.Framework;
using PnP.Framework.Entities;

Expand All @@ -12,46 +13,52 @@ namespace PnP.PowerShell.Commands
[Cmdlet(VerbsCommon.New, "PnPTenantSite")]
public class NewTenantSite : PnPAdminCmdlet
{
[Parameter(Mandatory = true)]
private const string ParameterSetName_Wait = "By Wait";

[Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string Title;

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string Url;

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string Owner = string.Empty;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public uint Lcid = 1033;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public string Template = "STS#0";

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = ParameterAttribute.AllParameterSets)]
public int TimeZone;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public double ResourceQuota = 0;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public double ResourceQuotaWarningLevel = 0;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public long StorageQuota = 100;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public long StorageQuotaWarningLevel = 100;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public SwitchParameter RemoveDeletedSite;

[Parameter(Mandatory = false)]

[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSetName_Wait)]
public SwitchParameter Wait;

[Obsolete("The Force parameter has been deprecated and is no longer required to be provided. It will be removed in a future version.")]
[Parameter(Mandatory = false)]
[Obsolete("The Force parameter has been deprecated and is no longer required to be provided. It will be removed in a future version.")]
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
public SwitchParameter Force;

[Parameter(Mandatory = false, ParameterSetName = ParameterSetName_Wait)]
public SharingCapabilities? SharingCapability;

protected override void ExecuteCmdlet()
{
if (!Url.ToLower().StartsWith("https://") && !Url.ToLower().StartsWith("http://"))
Expand All @@ -61,9 +68,22 @@ protected override void ExecuteCmdlet()
}
Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction;

Tenant.CreateSiteCollection(Url, Title, Owner, Template, (int)StorageQuota,
Guid newSiteId = Tenant.CreateSiteCollection(Url, Title, Owner, Template, (int)StorageQuota,
(int)StorageQuotaWarningLevel, TimeZone, (int)ResourceQuota, (int)ResourceQuotaWarningLevel, Lcid,
RemoveDeletedSite, Wait, Wait == true ? timeoutFunction : null);

if (newSiteId != Guid.Empty && Wait && SharingCapability.HasValue)
{
var props = Tenant.GetSitePropertiesByUrl(Url, true);
Tenant.Context.Load(props);
Tenant.Context.ExecuteQueryRetry();

props.SharingCapability = SharingCapability.Value;

var op = props.Update();
ClientContext.Load(op, i => i.IsComplete, i => i.PollingInterval);
ClientContext.ExecuteQueryRetry();
}
}

private bool TimeoutFunction(TenantOperationMessage message)
Expand Down