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

chore: Update Set-PnPHomeSite.md and SetHomeSite.cs #3986

Merged
merged 1 commit into from
May 30, 2024
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
35 changes: 34 additions & 1 deletion documentation/Set-PnPHomeSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Sets the home site for your tenant. The home site needs to be a communication si
## SYNTAX

```powershell
Set-PnPHomeSite -HomeSiteUrl <String> [VivaConnectionsDefaultStart <SwitchParameter>] [-Connection <PnPConnection>]
Set-PnPHomeSite -HomeSiteUrl <String> [VivaConnectionsDefaultStart <SwitchParameter>] [-Force <SwitchParameter>] [-DraftMode <SwitchParameter>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand All @@ -43,6 +43,13 @@ Set-PnPHomeSite -HomeSiteUrl "https://yourtenant.sharepoint.com/sites/myhome" -V

Sets the home site to the provided site collection url and keeps the Viva Connections landing experience to the SharePoint home site.

### EXAMPLE 3
```powershell
Set-PnPHomeSite -HomeSiteUrl "https://yourtenant.sharepoint.com/sites/myhome" -VivaConnectionsDefaultStart:$true -DraftMode:$true
```

Sets the home site to the provided site collection url and keeps the Viva Connections landing experience to the SharePoint home site but it will be in draft mode.

## PARAMETERS

### -Connection
Expand Down Expand Up @@ -86,6 +93,32 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -DraftMode
When set to $true, the DraftMode parameter will keep the Viva Connections landing experience to the SharePoint home site in draf mode.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Required: False
Position: Named
Default value: true
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
Use the -Force flag to bypass the confirmation question

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Required: False
Position: Named
Default value: true
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
74 changes: 67 additions & 7 deletions src/Commands/Admin/SetHomeSite.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.SharePoint.Client;

using Microsoft.SharePoint.PortalAndOrgNews;
using PnP.PowerShell.Commands.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Admin
Expand All @@ -15,17 +18,74 @@ public class SetHomeSite : PnPAdminCmdlet
[Parameter(Mandatory = false)]
public SwitchParameter VivaConnectionsDefaultStart;

[Parameter(Mandatory = false)]
public SwitchParameter Force;

[Parameter(Mandatory = false)]
public SwitchParameter DraftMode;

protected override void ExecuteCmdlet()
{
if (VivaConnectionsDefaultStart)
Tenant.EnsureProperties(t => t.IsMultipleVivaConnectionsFlightEnabled, t => t.IsVivaHomeFlightEnabled);

if (Tenant.IsMultipleVivaConnectionsFlightEnabled)
{
Tenant.SetSPHSiteWithConfigurations(HomeSiteUrl, VivaConnectionsDefaultStart);
if (Force.IsPresent || ShouldContinue("Before you update a home site or Viva Connections experiences, make sure you review the documentation at https://aka.ms/homesites. Continue?", string.Empty))
{
IEnumerable<TargetedSiteDetails> enumerable = Tenant.GetTargetedSitesDetails()?.Where((TargetedSiteDetails hs) => !hs.IsVivaBackendSite);
AdminContext.ExecuteQueryRetry();
bool flag = false;
if (enumerable == null || enumerable.Count() == 0)
{
Tenant.AddHomeSite(HomeSiteUrl, 1, null);
AdminContext.ExecuteQueryRetry();
flag = true;
}
else if (enumerable.Count() == 1 && !IsSameSiteUrl(enumerable.First().Url, HomeSiteUrl))
{
Tenant.RemoveTargetedSite(enumerable.First().SiteId);
AdminContext.ExecuteQueryRetry();
Tenant.AddHomeSite(HomeSiteUrl, 1, null);
AdminContext.ExecuteQuery();
flag = true;
}
HomeSiteConfigurationParam configurationParam = new()
{
vivaConnectionsDefaultStart = VivaConnectionsDefaultStart,
IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart,
isInDraftMode = DraftMode,
IsInDraftModePresent = DraftMode || flag
};
ClientResult<TargetedSiteDetails> clientResult = Tenant.UpdateTargetedSite(HomeSiteUrl, configurationParam);
AdminContext.ExecuteQueryRetry();
WriteObject(clientResult.Value);
}
}
else
else if (Force.IsPresent || ShouldContinue("Before you set a Home site, make sure you review the documentation at https://aka.ms/homesites. Continue?", string.Empty))
{
Tenant.SetSPHSite(HomeSiteUrl);
}
AdminContext.ExecuteQueryRetry();
Tenant.ValidateVivaHomeParameterExists(VivaConnectionsDefaultStart);
HomeSiteConfigurationParam configuration = null;
if (VivaConnectionsDefaultStart || DraftMode)
{
configuration = new HomeSiteConfigurationParam
{
vivaConnectionsDefaultStart = VivaConnectionsDefaultStart,
IsVivaConnectionsDefaultStartPresent = VivaConnectionsDefaultStart,
isInDraftMode = DraftMode,
IsInDraftModePresent = DraftMode
};
}
ClientResult<string> clientResult = Tenant.SetSPHSiteWithConfiguration(HomeSiteUrl, configuration);
AdminContext.ExecuteQueryRetry();
WriteObject(clientResult.Value);
}
}

private static bool IsSameSiteUrl(string url1, string url2)
{
Uri uri = new(url1);
Uri uri2 = new(url2);
return Uri.Compare(uri, uri2, UriComponents.Host | UriComponents.Path, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0;
}
}
}
Loading