Skip to content

Commit c31ee0f

Browse files
author
=
committed
Fixes pnp#2041
1 parent 05d0133 commit c31ee0f

7 files changed

+182
-58
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ 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
6667

6768
### Changed
6869

@@ -80,6 +81,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
8081
- 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)
8182
- 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)
8283
- 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)
84+
- Changed `Get-PnPSiteCollectionAppCatalogs` (plural) to `Get-PnPSiteCollectionAppCatalog` (singular) to follow the naming convention
8385

8486
### Fixed
8587

@@ -112,6 +114,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
112114
- 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)
113115
- Fixed `Add-PnPListItem` not showing field name when it has an improper value assigned to it [#2002](https://github.com/pnp/powershell/pull/2002)
114116
- 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)
117+
- Fixed `Get-PnPSiteCollectionAppCatalog` not returning updated site collection URLs if they had been renamed
115118

116119
### Removed
117120

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 [-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 -ExcludeDeletedSites
35+
```
36+
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
37+
38+
## PARAMETERS
39+
40+
### -ExcludeDeletedSites
41+
When provided, all site collections having site collection App Catalogs but residing in the tenant recycle bin, will be excluded
42+
43+
```yaml
44+
Type: SwitchParameter
45+
Parameter Sets: (All)
46+
47+
Required: False
48+
Position: Named
49+
Default value: None
50+
Accept pipeline input: False
51+
Accept wildcard characters: False
52+
```
53+
54+
### -Connection
55+
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.
56+
57+
```yaml
58+
Type: PnPConnection
59+
Parameter Sets: (All)
60+
61+
Required: False
62+
Position: Named
63+
Default value: None
64+
Accept pipeline input: False
65+
Accept wildcard characters: False
66+
```
67+
68+
### -Verbose
69+
When provided, additional debug statements will be shown while executing the cmdlet.
70+
71+
```yaml
72+
Type: SwitchParameter
73+
Parameter Sets: (All)
74+
75+
Required: False
76+
Position: Named
77+
Default value: None
78+
Accept pipeline input: False
79+
Accept wildcard characters: False
80+
```
81+
82+
## RELATED LINKS
83+
84+
[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,69 @@
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+
protected override void ExecuteCmdlet()
22+
{
23+
WriteVerbose("Retrieving all site collection App Catalogs from SharePoint Online");
24+
25+
var appCatalogsCsom = ClientContext.Web.TenantAppCatalog.SiteCollectionAppCatalogsSites;
26+
ClientContext.Load(appCatalogsCsom);
27+
ClientContext.ExecuteQueryRetry();
28+
29+
var appCatalogsLocalModel = appCatalogsCsom.Select(ac =>
30+
new SiteCollectionAppCatalog {
31+
AbsoluteUrl = ac.AbsoluteUrl,
32+
ErrorMessage = ac.ErrorMessage,
33+
SiteID = ac.SiteID
34+
}
35+
).ToArray();
36+
37+
WriteVerbose($"{appCatalogsLocalModel.Length} site collection App Catalog{(appCatalogsLocalModel.Length != 1 ? "s have" : " has")} been retrieved");
38+
39+
var results = new List<SiteCollectionAppCatalog>(appCatalogsLocalModel.Length);
40+
foreach (var appCatalogLocalModel in appCatalogsLocalModel)
41+
{
42+
if (appCatalogLocalModel.SiteID.HasValue)
43+
{
44+
try
45+
{
46+
WriteVerbose($"Validating site collection App Catalog at {appCatalogLocalModel.AbsoluteUrl}");
47+
48+
appCatalogLocalModel.AbsoluteUrl = Tenant.GetSitePropertiesById(appCatalogLocalModel.SiteID.Value, false).Url;
49+
results.Add(appCatalogLocalModel);
50+
}
51+
catch (Microsoft.SharePoint.Client.ServerException e) when (e.ServerErrorTypeName.Equals("Microsoft.Online.SharePoint.Common.SpoNoSiteException", StringComparison.InvariantCultureIgnoreCase))
52+
{
53+
if(!ExcludeDeletedSites.ToBool())
54+
{
55+
WriteVerbose($"Site collection App Catalog at {appCatalogLocalModel.AbsoluteUrl} regards a site that has been deleted");
56+
results.Add(appCatalogLocalModel);
57+
}
58+
else
59+
{
60+
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.");
61+
}
62+
}
63+
}
64+
}
65+
66+
WriteObject(results, true);
67+
}
68+
}
69+
}

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)