Introduction
Hi guys, let's start exploring a simple method to plug-out a specific associated site from a HubA and plug it into another HubB for our business needs without too much strain.
Precautions
Please go to the Modern Admin Centre by following this path:- Portal.Office.com>>Apps>>Admin>>Show All>>Admin centers>> SharePoint>> <TenantName>-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx >> Open it Now to reach the Modern SP Admin Center
Click on the active sites under the site section and check for your site collection to check which Hub it's associated to.
You can manually click on the change hub association to go to another hub.
However, if you have more operations similar to the above process, there's some easy PS coding that allows you to do it.
cls
#Plugging out the Given Associated Site from a Hub
$Tenantsite="https://<TenantName>-admin.sharepoint.com"
$site = "https://<TenantName>.sharepoint.com/sites/commc"
$Hubsite="https://<TenantName>.sharepoint.com/sites/Hubb"
Connect-pnponline -url $Tenantsite -useweblogin
Remove-PnPHubSiteAssociation -Site $site
#Plugging the Site to a Another Hub site using SPOnline PowerShell
$cred = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
Connect-sposervice $Tenantsite
Add-SPOHubSiteAssociation $site -HubSite $Hubsite
You can use the above code multiple times and run them parallelly with your different Site Collections for which you need to move them from one particular Hub Association to another Hub Association.
Note: A Hub can't be associated with another hub, but only site collections associations can be changed from one Hub to another Hub.