Skip to content
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 @@ -111,6 +111,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed an issue when trying to download a file using `Get-PnPFile` from a location that's deeply nested into folders and/or has a really long filename [PnP Core #1290](https://github.com/pnp/pnpcore/pull/1290)
- Fixed retrieving error detail in `Get-UPABulkImportStatus` cmdlet. [#3494](https://github.com/pnp/powershell/pull/3494)
- Fixed `Rename-PnPTenantSite` cmdlet to allow support for vanity tenant URLs. [#3533](https://github.com/pnp/powershell/pull/3533)
- Fixed `Add-PnPHubSiteAssociation` cmdlet to allow support for multi-geo scenario. [#3568](https://github.com/pnp/powershell/pull/3568)
- Fixed `Get-PnPAzureADUser`, `Get-PnPEntraIDUser`, `Add-PnPFlowOwner` and `Remove-PnPFlowOwner` not working when an UPN containing an apostrophe was passed in [#3570](https://github.com/pnp/powershell/pull/3570)

### Changed
Expand Down
32 changes: 30 additions & 2 deletions src/Commands/Admin/AddHubSiteAssociation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using PnP.PowerShell.Commands.Base;
using System.Management.Automation;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.Core.Model;
using System;

namespace PnP.PowerShell.Commands.Admin
{
Expand All @@ -17,8 +19,34 @@ public class AddHubSiteAssociation : PnPAdminCmdlet

protected override void ExecuteCmdlet()
{
Tenant.ConnectSiteToHubSite(Site.Url, HubSite.Url);
AdminContext.ExecuteQueryRetry();
try
{
Tenant.ConnectSiteToHubSite(Site.Url, HubSite.Url);
AdminContext.ExecuteQueryRetry();
}
catch
{
try
{
using (var primaryHub = PnPContext.Clone(HubSite.Url))
{
var primaryHubSite = primaryHub.Site.Get(p => p.HubSiteId, p => p.IsHubSite);

using (var associateHubSite = PnPContext.Clone(Site.Url))
{
var associateSite = associateHubSite.Site.Get(p => p.HubSiteId, p => p.IsHubSite);
if (associateSite.HubSiteId == Guid.Empty)
{
var resultJoin = associateSite.JoinHubSite(primaryHubSite.HubSiteId);
}
}
}
}
catch
{
throw;
}
}
}
}
}