Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to Get-PnPHubSiteChild #2033

Merged
merged 3 commits into from
Jun 27, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
29 changes: 18 additions & 11 deletions documentation/Get-PnPHubSiteChild.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Retrieves all sites associated to a specific hub site
## SYNTAX

```powershell
Get-PnPHubSiteChild -Identity <HubSitePipeBind> [-Connection <PnPConnection>] [<CommonParameters>]
Get-PnPHubSiteChild [-Identity <HubSitePipeBind>] [-Connection <PnPConnection>] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -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
```
Expand All @@ -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
```

Expand Down
26 changes: 20 additions & 6 deletions src/Commands/Admin/GetHubSiteChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,38 @@ 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()
{
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
Expand Down