Skip to content

Commit b6e6475

Browse files
gautamdshethGautam ShethKoenZomers
authored
Fix #1911: Add-PnPHubSiteAssociation cmdlet to support (#3568)
* Fix #1911: Add-PnPHubSiteAssociation cmdlet to support multi-geo scenario * Update CHANGELOG.md --------- Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com> Co-authored-by: Koen Zomers <koen@zomers.eu>
1 parent c9f222e commit b6e6475

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
111111
- 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)
112112
- Fixed retrieving error detail in `Get-UPABulkImportStatus` cmdlet. [#3494](https://github.com/pnp/powershell/pull/3494)
113113
- Fixed `Rename-PnPTenantSite` cmdlet to allow support for vanity tenant URLs. [#3533](https://github.com/pnp/powershell/pull/3533)
114+
- Fixed `Add-PnPHubSiteAssociation` cmdlet to allow support for multi-geo scenario. [#3568](https://github.com/pnp/powershell/pull/3568)
114115
- 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)
115116

116117
### Changed

src/Commands/Admin/AddHubSiteAssociation.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using PnP.PowerShell.Commands.Base;
44
using System.Management.Automation;
55
using PnP.PowerShell.Commands.Base.PipeBinds;
6+
using PnP.Core.Model;
7+
using System;
68

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

1820
protected override void ExecuteCmdlet()
1921
{
20-
Tenant.ConnectSiteToHubSite(Site.Url, HubSite.Url);
21-
AdminContext.ExecuteQueryRetry();
22+
try
23+
{
24+
Tenant.ConnectSiteToHubSite(Site.Url, HubSite.Url);
25+
AdminContext.ExecuteQueryRetry();
26+
}
27+
catch
28+
{
29+
try
30+
{
31+
using (var primaryHub = PnPContext.Clone(HubSite.Url))
32+
{
33+
var primaryHubSite = primaryHub.Site.Get(p => p.HubSiteId, p => p.IsHubSite);
34+
35+
using (var associateHubSite = PnPContext.Clone(Site.Url))
36+
{
37+
var associateSite = associateHubSite.Site.Get(p => p.HubSiteId, p => p.IsHubSite);
38+
if (associateSite.HubSiteId == Guid.Empty)
39+
{
40+
var resultJoin = associateSite.JoinHubSite(primaryHubSite.HubSiteId);
41+
}
42+
}
43+
}
44+
}
45+
catch
46+
{
47+
throw;
48+
}
49+
}
2250
}
2351
}
2452
}

0 commit comments

Comments
 (0)