Skip to content

Commit 9e6f991

Browse files
Changes to Get-PnPSiteCollectionAppCatalogs (#2044)
* Fixes #2041 * Added additional CurrentSite parameter Co-authored-by: = <=> Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent 3bf5279 commit 9e6f991

7 files changed

+224
-58
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6363
- Added `Get-Microsoft365GroupYammerCommunity` cmdlet to retrieve details on the Yammer Community connected to a Microsoft 365 Group [#2038](https://github.com/pnp/powershell/pull/2038)
6464
- Added `Get-Microsoft365GroupTeam` cmdlet to retrieve details on the Microsoft Teams team connected to a Microsoft 365 Group [#2038](https://github.com/pnp/powershell/pull/2038)
6565
- Added `Get-Microsoft365GroupEndpoints` cmdlet to retrieve details on all endpoints connected to a Microsoft 365 Group [#2038](https://github.com/pnp/powershell/pull/2038)
66+
- Added `-ExcludeDeletedSites` optional parameter to `Get-PnPSiteCollectionAppCatalogs` which allows for site collections with App Catalogs that are in the recycle bin to be exluded from the results [#2044](https://github.com/pnp/powershell/pull/2044)
67+
- Added `-CurrentSite` optional parameter to `Get-PnPSiteCollectionAppCatalogs` which allows for checking if the currently connected to site has a site collection App Catalogs provisioned on it [#2044](https://github.com/pnp/powershell/pull/2044)
6668

6769
### Changed
6870

@@ -80,6 +82,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
8082
- 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)
8183
- 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)
8284
- 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)
85+
- Changed `Get-PnPSiteCollectionAppCatalogs` (plural) to `Get-PnPSiteCollectionAppCatalog` (singular) to follow the naming convention [#2044](https://github.com/pnp/powershell/pull/2044)
8386

8487
### Fixed
8588

@@ -112,6 +115,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
112115
- 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)
113116
- Fixed `Add-PnPListItem` not showing field name when it has an improper value assigned to it [#2002](https://github.com/pnp/powershell/pull/2002)
114117
- 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)
118+
- Fixed `Get-PnPSiteCollectionAppCatalog` not returning updated site collection URLs if they had been renamed [#2044](https://github.com/pnp/powershell/pull/2044)
115119
- Fixed cmdlets inheriting from PnPAdminCmdlet not working well on vanity domain SharePoint Online tenants [#2052](https://github.com/pnp/powershell/pull/2052)
116120
- Fixed `Copy-PnPList` throwing an unauthorized exception when using it with a non SharePoint Online administrator user [#2054](https://github.com/pnp/powershell/pull/2054)
117121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Get-PnPSiteCollectionAppCatalog
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPSiteCollectionAppCatalog.html
8+
---
9+
10+
# Get-PnPSiteCollectionAppCatalog
11+
12+
## SYNOPSIS
13+
Returns all site collection scoped app catalogs that exist on the tenant
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Get-PnPSiteCollectionAppCatalog [-CurrentSite <SwitchParameter>] [-ExcludeDeletedSites <SwitchParameter>] [-Connection <PnPConnection>] [-Verbose] [<CommonParameters>]
19+
```
20+
21+
## DESCRIPTION
22+
Returns all the site collection scoped app catalogs that exist on the tenant
23+
24+
## EXAMPLES
25+
26+
### EXAMPLE 1
27+
```powershell
28+
Get-PnPSiteCollectionAppCatalog
29+
```
30+
Will return all the site collection app catalogs that exist on the tenant, including those that may be in the tenant recycle bin
31+
32+
### EXAMPLE 2
33+
```powershell
34+
Get-PnPSiteCollectionAppCatalog -CurrentSite
35+
```
36+
Will return the site collection app catalog for the currently connected to site, if it has one. Otherwise it will yield no result.
37+
38+
### EXAMPLE 2
39+
```powershell
40+
Get-PnPSiteCollectionAppCatalog -ExcludeDeletedSites
41+
```
42+
Will return all the site collection app catalogs that exist on the tenant excluding the site collections having App Catalogs that are in the tenant recycle bin
43+
44+
## PARAMETERS
45+
46+
### -CurrentSite
47+
When provided, it will check if the currently connected to site has a site collection App Catalog and will return information on it. If the current site holds no site collection App Catalog, an empty response will be returned.
48+
49+
```yaml
50+
Type: SwitchParameter
51+
Parameter Sets: (All)
52+
53+
Required: False
54+
Position: Named
55+
Default value: None
56+
Accept pipeline input: False
57+
Accept wildcard characters: False
58+
```
59+
60+
### -ExcludeDeletedSites
61+
When provided, all site collections having site collection App Catalogs but residing in the tenant recycle bin, will be excluded
62+
63+
```yaml
64+
Type: SwitchParameter
65+
Parameter Sets: (All)
66+
67+
Required: False
68+
Position: Named
69+
Default value: None
70+
Accept pipeline input: False
71+
Accept wildcard characters: False
72+
```
73+
74+
### -Connection
75+
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.
76+
77+
```yaml
78+
Type: PnPConnection
79+
Parameter Sets: (All)
80+
81+
Required: False
82+
Position: Named
83+
Default value: None
84+
Accept pipeline input: False
85+
Accept wildcard characters: False
86+
```
87+
88+
### -Verbose
89+
When provided, additional debug statements will be shown while executing the cmdlet.
90+
91+
```yaml
92+
Type: SwitchParameter
93+
Parameter Sets: (All)
94+
95+
Required: False
96+
Position: Named
97+
Default value: None
98+
Accept pipeline input: False
99+
Accept wildcard characters: False
100+
```
101+
102+
## RELATED LINKS
103+
104+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Get-PnPSiteCollectionAppCatalogs.md

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Management.Automation;
5+
using Microsoft.SharePoint.Client;
6+
using PnP.PowerShell.Commands.Attributes;
7+
using PnP.PowerShell.Commands.Base;
8+
using PnP.PowerShell.Commands.Model.SharePoint;
9+
10+
namespace PnP.PowerShell.Commands
11+
{
12+
[Cmdlet(VerbsCommon.Get, "PnPSiteCollectionAppCatalog")]
13+
[Alias("Get-PnPSiteCollectionAppCatalogs")]
14+
[WriteAliasWarning("Please use 'Get-PnPSiteCollectionAppCatalog' (singular). The alias 'Get-PnPSiteCollectionAppCatalogs' (plural) will be removed in a future release.")]
15+
[OutputType(typeof(IEnumerable<SiteCollectionAppCatalog>))]
16+
public class GetSiteCollectionAppCatalog : PnPAdminCmdlet
17+
{
18+
[Parameter(Mandatory = false)]
19+
public SwitchParameter ExcludeDeletedSites;
20+
21+
[Parameter(Mandatory = false)]
22+
public SwitchParameter CurrentSite;
23+
24+
protected override void ExecuteCmdlet()
25+
{
26+
WriteVerbose("Retrieving all site collection App Catalogs from SharePoint Online");
27+
28+
var appCatalogsCsom = ClientContext.Web.TenantAppCatalog.SiteCollectionAppCatalogsSites;
29+
ClientContext.Load(appCatalogsCsom);
30+
ClientContext.ExecuteQueryRetry();
31+
32+
var appCatalogsLocalModel = appCatalogsCsom.Select(ac =>
33+
new SiteCollectionAppCatalog {
34+
AbsoluteUrl = ac.AbsoluteUrl,
35+
ErrorMessage = ac.ErrorMessage,
36+
SiteID = ac.SiteID
37+
}
38+
).ToList();
39+
40+
WriteVerbose($"{appCatalogsLocalModel.Count} site collection App Catalog{(appCatalogsLocalModel.Count != 1 ? "s have" : " has")} been retrieved");
41+
42+
if(CurrentSite.ToBool())
43+
{
44+
SiteContext.Site.EnsureProperties(s => s.Id);
45+
46+
WriteVerbose($"Filtering down to only the current site at {Connection.Url} with ID {SiteContext.Site.Id}");
47+
var currentSite = appCatalogsLocalModel.FirstOrDefault(a => a.SiteID.HasValue && a.SiteID.Value == SiteContext.Site.Id);
48+
49+
appCatalogsLocalModel.Clear();
50+
51+
if(currentSite == null)
52+
{
53+
WriteVerbose($"Current site at {Connection.Url} with ID {SiteContext.Site.Id} does not have a site collection App Catalog on it");
54+
return;
55+
}
56+
57+
appCatalogsLocalModel.Add(currentSite);
58+
}
59+
60+
var results = new List<SiteCollectionAppCatalog>(appCatalogsLocalModel.Count);
61+
foreach (var appCatalogLocalModel in appCatalogsLocalModel)
62+
{
63+
if (appCatalogLocalModel.SiteID.HasValue)
64+
{
65+
try
66+
{
67+
WriteVerbose($"Validating site collection App Catalog at {appCatalogLocalModel.AbsoluteUrl}");
68+
69+
appCatalogLocalModel.AbsoluteUrl = Tenant.GetSitePropertiesById(appCatalogLocalModel.SiteID.Value, false).Url;
70+
results.Add(appCatalogLocalModel);
71+
}
72+
catch (Microsoft.SharePoint.Client.ServerException e) when (e.ServerErrorTypeName.Equals("Microsoft.Online.SharePoint.Common.SpoNoSiteException", StringComparison.InvariantCultureIgnoreCase))
73+
{
74+
if(!ExcludeDeletedSites.ToBool())
75+
{
76+
WriteVerbose($"Site collection App Catalog at {appCatalogLocalModel.AbsoluteUrl} regards a site that has been deleted");
77+
results.Add(appCatalogLocalModel);
78+
}
79+
else
80+
{
81+
WriteVerbose($"Site collection App Catalog at {appCatalogLocalModel.AbsoluteUrl} regards a site that has been deleted. Since the {nameof(ExcludeDeletedSites)} flag has been provided, it will not be included in the results.");
82+
}
83+
}
84+
}
85+
}
86+
87+
WriteObject(results, true);
88+
}
89+
}
90+
}

src/Commands/Admin/GetSiteCollectionAppCatalogs.cs

-19
This file was deleted.

src/Commands/Admin/GetTenantSite.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.Online.SharePoint.TenantAdministration;
55
using Microsoft.SharePoint.Client;
66
using PnP.PowerShell.Commands.Base;
7-
using PnP.PowerShell.Commands.Enums;
87
using System.Collections.Generic;
98
using Microsoft.Online.SharePoint.TenantManagement;
109
using PnP.PowerShell.Commands.Base.PipeBinds;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace PnP.PowerShell.Commands.Model.SharePoint
4+
{
5+
/// <summary>
6+
/// All properties regarding a site collection scoped App Catalog
7+
/// </summary>
8+
public class SiteCollectionAppCatalog
9+
{
10+
/// <summary>
11+
/// The full Url to the location of the App Catalog in the tenant
12+
/// </summary>
13+
public string AbsoluteUrl { get; set; }
14+
15+
/// <summary>
16+
/// Informational message regarding the provisioning of the App Catalog
17+
/// </summary>
18+
public string ErrorMessage { get; set; }
19+
20+
/// <summary>
21+
/// Unique identifier of the site on which this App Catalog is located
22+
/// </summary>
23+
public Guid? SiteID { get; set; }
24+
25+
}
26+
}

0 commit comments

Comments
 (0)