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

Commit edfd2e1

Browse files
Merge pull request #2005 from erwinvanhunen/dev
April 2019 Release
2 parents 4fcc7c1 + fe88730 commit edfd2e1

File tree

5 files changed

+111
-7
lines changed

5 files changed

+111
-7
lines changed

Commands/Admin/GetHomeSite.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if !ONPREMISES
2+
using Microsoft.SharePoint.Client;
3+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
4+
using SharePointPnP.PowerShell.Commands.Base;
5+
using System.Management.Automation;
6+
7+
namespace SharePointPnP.PowerShell.Commands.Admin
8+
{
9+
[Cmdlet(VerbsCommon.Get, "PnPHomeSite")]
10+
[CmdletHelp("Returns the home site url for your tenant",
11+
SupportedPlatform = CmdletSupportedPlatform.Online,
12+
Category = CmdletHelpCategory.TenantAdmin)]
13+
[CmdletExample(
14+
Code = @"PS:> Get-PnPHomeSite",
15+
Remarks = @"Returns the home site url for your tenant", SortOrder = 1)]
16+
public class GetHomeSite : PnPAdminCmdlet
17+
{
18+
protected override void ExecuteCmdlet()
19+
{
20+
var results = Tenant.GetSPHSiteUrl();
21+
ClientContext.ExecuteQueryRetry();
22+
WriteObject(results.Value);
23+
}
24+
}
25+
}
26+
#endif

Commands/Admin/NewTenantSite.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System;
2-
using System.Management.Automation;
3-
using Microsoft.SharePoint.Client;
1+
using Microsoft.SharePoint.Client;
42
using OfficeDevPnP.Core;
3+
#if ONPREMISES
54
using OfficeDevPnP.Core.Entities;
5+
#endif
66
using SharePointPnP.PowerShell.CmdletHelpAttributes;
77
using SharePointPnP.PowerShell.Commands.Base;
8+
using System;
9+
using System.Management.Automation;
810
using Resources = SharePointPnP.PowerShell.Commands.Properties.Resources;
911

1012

@@ -17,11 +19,11 @@ namespace SharePointPnP.PowerShell.Commands
1719
Category = CmdletHelpCategory.TenantAdmin)]
1820
[CmdletExample(
1921
Code = @"PS:> New-PnPTenantSite -Title Contoso -Url https://tenant.sharepoint.com/sites/contoso -Owner [email protected] -TimeZone 4 -Template STS#0",
20-
Remarks = @"This will add a site collection with the title 'Contoso', the url 'https://tenant.sharepoint.com/sites/contoso', the timezone 'UTC+01:00',the owner '[email protected]' and the template used will be STS#0, a TeamSite",
22+
Remarks = @"This will add a site collection with the title 'Contoso', the url 'https://tenant.sharepoint.com/sites/contoso', the timezone 'UTC+01:00',the owner '[email protected]' and the template used will be STS#0, a TeamSite",
2123
SortOrder = 1)]
2224
[CmdletExample(
2325
Code = @"PS:> New-PnPTenantSite -Title Contoso -Url /sites/contososite -Owner [email protected] -TimeZone 4 -Template STS#0",
24-
Remarks = @"This will add a site collection with the title 'Contoso', the url 'https://tenant.sharepoint.com/sites/contososite' of which the base part will be picked up from your current connection, the timezone 'UTC+01:00', the owner '[email protected]' and the template used will be STS#0, a TeamSite",
26+
Remarks = @"This will add a site collection with the title 'Contoso', the url 'https://tenant.sharepoint.com/sites/contososite' of which the base part will be picked up from your current connection, the timezone 'UTC+01:00', the owner '[email protected]' and the template used will be STS#0, a TeamSite",
2527
SortOrder = 2)]
2628
[CmdletRelatedLink(
2729
Text = "Locale IDs",
@@ -40,7 +42,8 @@ public class NewTenantSite : PnPAdminCmdlet
4042
[Parameter(Mandatory = true, HelpMessage = @"Specifies the full URL of the new site collection. It must be in a valid managed path in the company's site. For example, for company contoso, valid managed paths are https://contoso.sharepoint.com/sites and https://contoso.sharepoint.com/teams.")]
4143
public string Url;
4244

43-
[Parameter(Mandatory = false, HelpMessage = @"Specifies the description of the new site collection")]
45+
[Obsolete("This parameter is currently ignored due to server side API issues when setting this value.")]
46+
[Parameter(Mandatory = false, HelpMessage = @"Specifies the description of the new site collection. Setting a value for this parameter will override the Wait parameter as we have to set the description after the site has been created.")]
4447
public string Description = string.Empty;
4548

4649
[Parameter(Mandatory = true, HelpMessage = @"Specifies the user name of the site collection's primary owner. The owner must be a user instead of a security group or an email-enabled security group.")]
@@ -103,11 +106,15 @@ protected override void ExecuteCmdlet()
103106
entity.UserCodeMaximumLevel = ResourceQuota;
104107
entity.UserCodeWarningLevel = ResourceQuotaWarningLevel;
105108
entity.Lcid = Lcid;
106-
107109
Tenant.CreateSiteCollection(entity);
108110
#else
109111
Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction;
110112

113+
if (MyInvocation.BoundParameters.ContainsKey("Description"))
114+
{
115+
// We have to fall back to synchronous behaviour as we have to wait for the site to be present in order to set the description.
116+
Wait = true;
117+
}
111118

112119
Tenant.CreateSiteCollection(Url, Title, Owner, Template, (int)StorageQuota,
113120
(int)StorageQuotaWarningLevel, TimeZone, (int)ResourceQuota, (int)ResourceQuotaWarningLevel, Lcid,

Commands/Admin/RemoveHomeSite.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#if !ONPREMISES
2+
using Microsoft.SharePoint.Client;
3+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
4+
using SharePointPnP.PowerShell.Commands.Base;
5+
using System.Management.Automation;
6+
7+
namespace SharePointPnP.PowerShell.Commands.Admin
8+
{
9+
[Cmdlet(VerbsCommon.Remove, "PnPHomeSite")]
10+
[CmdletHelp("Removes the currently set site as the home site",
11+
SupportedPlatform = CmdletSupportedPlatform.Online,
12+
Category = CmdletHelpCategory.TenantAdmin)]
13+
[CmdletExample(
14+
Code = @"PS:> Remove-PnPHomeSite",
15+
Remarks = @"Removes the currently set site as the home site", SortOrder = 1)]
16+
public class RemoveHomeSite : PnPAdminCmdlet
17+
{
18+
[Parameter(Mandatory = false, HelpMessage = "Specifying the Force parameter will skip the confirmation question.")]
19+
public SwitchParameter Force;
20+
21+
protected override void ExecuteCmdlet()
22+
{
23+
var homesiteUrl = Tenant.GetSPHSiteUrl();
24+
ClientContext.ExecuteQueryRetry();
25+
if (!string.IsNullOrEmpty(homesiteUrl.Value))
26+
{
27+
if (Force || ShouldContinue($"Remove {homesiteUrl.Value} as the home site?", Properties.Resources.Confirm))
28+
{
29+
Tenant.RemoveSPHSite();
30+
ClientContext.ExecuteQueryRetry();
31+
}
32+
}
33+
else
34+
{
35+
WriteWarning("There is currently not site collection set as a home site in your tenant.");
36+
}
37+
}
38+
}
39+
}
40+
#endif

Commands/Admin/SetHomeSite.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#if !ONPREMISES
2+
using Microsoft.SharePoint.Client;
3+
using SharePointPnP.PowerShell.CmdletHelpAttributes;
4+
using SharePointPnP.PowerShell.Commands.Base;
5+
using System.Management.Automation;
6+
7+
namespace SharePointPnP.PowerShell.Commands.Admin
8+
{
9+
[Cmdlet(VerbsCommon.Set, "PnPHomeSite")]
10+
[CmdletHelp("Sets the home site for your tenant",
11+
SupportedPlatform = CmdletSupportedPlatform.Online,
12+
Category = CmdletHelpCategory.TenantAdmin)]
13+
[CmdletExample(
14+
Code = @"PS:> Set-PnPHomeSite -Url https://yourtenant.sharepoint.com/sites/myhome",
15+
Remarks = @"Sets the home site to the provided site collection url", SortOrder = 1)]
16+
public class SetHomeSite : PnPAdminCmdlet
17+
{
18+
[Parameter(Mandatory = true, HelpMessage = "The url of the site to set as the home site")]
19+
public string Url;
20+
21+
protected override void ExecuteCmdlet()
22+
{
23+
Tenant.SetSPHSite(Url);
24+
ClientContext.ExecuteQueryRetry();
25+
}
26+
}
27+
}
28+
#endif

Commands/SharePointPnP.PowerShell.Commands.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@
538538
<Compile Include="Admin\AddOffice365GroupToSite.cs" />
539539
<Compile Include="Admin\AddSiteCollectionAppCatalog.cs" />
540540
<Compile Include="Admin\AddTenantTheme.cs" />
541+
<Compile Include="Admin\GetHomeSite.cs" />
542+
<Compile Include="Admin\RemoveHomeSite.cs" />
543+
<Compile Include="Admin\SetHomeSite.cs" />
541544
<Compile Include="Apps\DenyTenantServicePrincipalPermissionRequest.cs" />
542545
<Compile Include="Apps\DisableTenantServicePrincipal.cs" />
543546
<Compile Include="Apps\GrantTenantServicePrincipalPermission.cs" />

0 commit comments

Comments
 (0)