O365 CLI Register Hubsite and get ID
-
06-02-2021 - |
Question
I am currently writing a script using the O365 CLI. The aim of the script is to register a site collection as a hub site. I am stuck at the end result of which I want to capture the ID.
The script so far does the following:
o365 spo login "https://mytenant-admin.sharepoint.com/"
$hubsite = o365 spo hubsite register --url https://mytenant.sharepoint.com/sites/hubsite
Write-Host "Hubsite ID: $hubsite.ID"
It is a simple enough script however the "Write-Host" keeps returning blank. If I just enter $hubsite then I get the similar to the following:
Description : null ID : 1af04d03-d2a9-4eb4-aa9c-000000 LogoUrl : null RequiresJoinApproval: false SiteDesignId : 00000000-0000-0000-0000-000000000000 SiteId : 1af04d03-d2a9-4eb4-aa9c-2acbfc952c00 SiteUrl : https://mytenant.sharepoint.com/sites/hubsite Targets : null TenantInstanceId : 35da7502-e9d2-4684-0000-d84b98b0000 Title : Communication Site
Can please anyone help with where I am going wrong?
No correct solution
OTHER TIPS
I managed to resolve this by outputting the results to JSON, instead I now have the following:
o365 spo login "https://mytenant-admin.sharepoint.com/"
$hubsite = o365 spo hubsite register --url https://mytenant.sharepoint.com/sites/hubsite -output json | ConvertFrom-Json
Write-Host "Hubsite ID: $hubsite.ID"