From 0d94b5a209360a03f900892b9c1c17a5b8c4b5bc Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Mon, 27 Jun 2022 09:27:54 +0200 Subject: [PATCH] Modifications to `Get-PnPHubSiteChild` (#2033) * -Identity is now optional, clear error message gets shown when requesting this for a site that's not a hub site * Added PR reference Co-authored-by: = <=> Co-authored-by: Gautam Sheth --- CHANGELOG.md | 3 +++ documentation/Get-PnPHubSiteChild.md | 29 +++++++++++++++++---------- src/Commands/Admin/GetHubSiteChild.cs | 26 ++++++++++++++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 627842e29..bd80affc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Service Health cmdlets have been improved and are now consistent with other cmdlets to handle pagination [#1938](https://github.com/pnp/powershell/pull/1938) - Changed that almost every cmdlet now supports passing in a specific connection using `-Connection`. If omitted, the default connection will be used. [#1949](https://github.com/pnp/powershell/pull/1949), [#2011](https://github.com/pnp/powershell/pull/2011), [#1958](https://github.com/pnp/powershell/pull/1958) - Changed connecting with `Connect-PnPOnline -Credentials` now throwing a clear exception when making a typo in the hostname instead of getting stuck [#686](https://github.com/pnp/pnpframework/pull/686) +- Changed `Get-PnPHubSiteChild` to have its `-Identity` parameter become optional. If not provided, the currently connected to site will be used. [#2033](https://github.com/pnp/powershell/pull/2033) ### Fixed @@ -103,6 +104,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed `Update-PnPSiteClassification`, it was ignoring the `Settings` parameter. It will now be processed. [#1989](https://github.com/pnp/powershell/pull/1989) - Fixed `Register-PnPAzureADApp` issue with app creation after the connection related changes. [#1993](https://github.com/pnp/powershell/pull/1993) - Fixed `Get-PnPFileVersion` not able to correctly use piping on the returned object. [#1997](https://github.com/pnp/powershell/pull/1997) +- Fixed `Add-PnPListItem` not showing field name when it has an improper value assigned to it [#2002](https://github.com/pnp/powershell/pull/202) +- Fixed `Get-PnPHubSiteChild` throwing an exception when passing in a URL that is actually not a hub site [#2033](https://github.com/pnp/powershell/pull/2033) - Fixed `Add-PnPListItem` not showing field name when it has an improper value assigned to it [#2002](https://github.com/pnp/powershell/pull/2002) - Fixed connecting using `Connect-PnPOnline -Interactive -ClientId` not working well when already having an App-Only connection using the same ClientId [#2035](https://github.com/pnp/powershell/pull/2035) diff --git a/documentation/Get-PnPHubSiteChild.md b/documentation/Get-PnPHubSiteChild.md index 7f67b2de8..3a6858a6f 100644 --- a/documentation/Get-PnPHubSiteChild.md +++ b/documentation/Get-PnPHubSiteChild.md @@ -20,7 +20,7 @@ Retrieves all sites associated to a specific hub site ## SYNTAX ```powershell -Get-PnPHubSiteChild -Identity [-Connection ] [] +Get-PnPHubSiteChild [-Identity ] [-Connection ] [] ``` ## DESCRIPTION @@ -30,12 +30,19 @@ Retrieves all sites associated to a specific hub site ### EXAMPLE 1 ```powershell +Get-PnPHubSiteChild +``` + +Returns the sites which are associated to the currently connected to hub site + +### EXAMPLE 2 +```powershell Get-PnPHubSiteChild -Identity "https://contoso.sharepoint.com/sites/myhubsite" ``` Returns the sites which are associated with the provided hub site as their hub site -### EXAMPLE 2 +### EXAMPLE 3 ```powershell Get-PnPHubSite | Get-PnPHubSiteChild ``` @@ -44,31 +51,31 @@ Returns all sites that are associated to a hub site ## PARAMETERS -### -Connection -Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. +### -Identity +The URL, Id or instance of the hubsite for which to receive the sites refering to it. If not provided, the currently connected to site will be used. ```yaml -Type: PnPConnection +Type: HubSitePipeBind Parameter Sets: (All) Required: False Position: Named Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -Identity -The URL, Id or instance of the hubsite for which to receive the sites refering to it +### -Connection +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. ```yaml -Type: HubSitePipeBind +Type: PnPConnection Parameter Sets: (All) -Required: True +Required: False Position: Named Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: False Accept wildcard characters: False ``` diff --git a/src/Commands/Admin/GetHubSiteChild.cs b/src/Commands/Admin/GetHubSiteChild.cs index d8c5b700e..44a403f36 100644 --- a/src/Commands/Admin/GetHubSiteChild.cs +++ b/src/Commands/Admin/GetHubSiteChild.cs @@ -11,7 +11,7 @@ namespace PnP.PowerShell.Commands.Admin [Cmdlet(VerbsCommon.Get, "PnPHubSiteChild")] public class GetHubSiteChild : PnPAdminCmdlet { - [Parameter(ValueFromPipeline = true, Mandatory = true)] + [Parameter(ValueFromPipeline = true, Mandatory = false)] public HubSitePipeBind Identity; protected override void ExecuteCmdlet() @@ -19,16 +19,30 @@ protected override void ExecuteCmdlet() HubSiteProperties hubSiteProperties; try { - hubSiteProperties = Identity.GetHubSite(Tenant); + if (ParameterSpecified(nameof(Identity))) + { + hubSiteProperties = Identity.GetHubSite(Tenant); + } + else + { + hubSiteProperties = Tenant.GetHubSitePropertiesByUrl(Connection.Url); + } hubSiteProperties.EnsureProperty(h => h.ID); } - catch (ServerException ex) + catch (ServerObjectNullReferenceException) { - if (ex.ServerErrorTypeName.Equals("System.IO.FileNotFoundException")) + if (ParameterSpecified(nameof(Identity))) { - throw new ArgumentException(Resources.SiteNotFound, nameof(Identity)); + throw new ArgumentException($"Unable to retrieve hub child sites of site provided through -{nameof(Identity)}. This could be caused by the site not being a hub site.", nameof(Identity)); } - throw; + else + { + throw new PSInvalidOperationException($"Unable to retrieve hub child sites of the current site {Connection.Url}. This could be caused by this site not being a hub site."); + } + } + catch (ServerException e) when (e.ServerErrorTypeName.Equals("System.IO.FileNotFoundException")) + { + throw new ArgumentException(Resources.SiteNotFound, nameof(Identity)); } // Get the ID of the hubsite for which we need to find child sites