-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2920 from gautamdsheth/feature/acs-list
Feature: Added cmdlets to retrive SP Addins and ACS principals
- Loading branch information
Showing
6 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPAzureACSPrincipal.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Get-PnPAzureACSPrincipal | ||
--- | ||
|
||
# Get-PnPAzureACSPrincipal | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* SharePoint: Access to the SharePoint Tenant Administration site | ||
|
||
Returns the list of Azure ACS Principals | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Get-PnPAzureACSPrincipal [-Scope <AzureACSPrincipalScope>] [-IncludeSubsites <SwitchParameter>] [-Connection <PnPConnection>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Get-PnPAzureACSPrincipal | ||
``` | ||
|
||
Returns the Azure ACS principals | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
Get-PnPAzureACSPrincipal -IncludeSubsites | ||
``` | ||
|
||
Returns the lists of Azure ACS principals installed in your site collection as well as the subsites. | ||
|
||
### EXAMPLE 3 | ||
```powershell | ||
Get-PnPAzureACSPrincipal -Scope Tenant | ||
``` | ||
|
||
Returns the lists of Azure ACS principals installed in your Tenant. | ||
|
||
### EXAMPLE 4 | ||
```powershell | ||
Get-PnPAzureACSPrincipal -Scope All -IncludeSubsites | ||
``` | ||
|
||
Returns the lists of all Azure ACS principals installed in your Tenant including subsites. This a very heavy operation, so it might take some time before we get the results. | ||
|
||
## 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. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Scope | ||
When specified, it determines the scope of the Azure ACS principals. | ||
Supported values are `List, Web, Site, Tenant , All`. | ||
|
||
```yaml | ||
Type: Enum (AzureACSPrincipalScope) | ||
Parameter Sets: (All) | ||
Required: False | ||
Position: Named | ||
Default value: List | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -IncludeSubsites | ||
When specified, it determines whether we should use also search the subsites of the connected site collection and lists the Azure ACS principals. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
## RELATED LINKS | ||
|
||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPSharePointAddIn.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Get-PnPSharePointAddIn | ||
--- | ||
|
||
# Get-PnPSharePointAddIn | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* SharePoint: Access to the SharePoint Tenant Administration site | ||
|
||
Returns the list of SharePoint addins installed in the site collection | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Get-PnPSharePointAddIn [-IncludeSubsites <SwitchParameter>] [-Connection <PnPConnection>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Get-PnPSharePointAddIn | ||
``` | ||
|
||
Returns the SharePoint addins installed in your site collection | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
Get-PnPSharePointAddIn -IncludeSubsites | ||
``` | ||
|
||
Returns the SharePoint addins installed in your site collection as well as the subsites. | ||
|
||
## 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. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -IncludeSubsites | ||
When specified, it determines whether we should use also search the subsites of the connected site collection and lists the installed AddIns. | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Microsoft.SharePoint.Client; | ||
using PnP.Core.Admin.Model.SharePoint; | ||
using PnP.Core.Services; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Enums; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Apps | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPAzureACSPrincipal")] | ||
[OutputType(typeof(List<IACSPrincipal>))] | ||
public class GetAzureACSPrincipal : PnPAdminCmdlet | ||
{ | ||
[Parameter(Mandatory = false)] | ||
public AzureACSPrincipalScope Scope; | ||
|
||
[Parameter(Mandatory = false)] | ||
public SwitchParameter IncludeSubsites; | ||
protected override void ExecuteCmdlet() | ||
{ | ||
var tenantAdminSiteUrl = Connection.TenantAdminUrl ?? UrlUtilities.GetTenantAdministrationUrl(ClientContext.Url); | ||
|
||
VanityUrlOptions vanityUrlOptions = new() | ||
{ | ||
AdminCenterUri = new Uri(tenantAdminSiteUrl) | ||
}; | ||
|
||
using var context = ClientContext.Clone(Connection.Url); | ||
|
||
using var pnpContext = Framework.PnPCoreSdk.Instance.GetPnPContext(context); | ||
|
||
if (Scope == AzureACSPrincipalScope.Tenant) | ||
{ | ||
// First load a list possible principal app ids from Azure AD | ||
var legacyServicePrincipals = pnpContext.GetSiteCollectionManager().GetLegacyServicePrincipals(); | ||
if (legacyServicePrincipals != null) | ||
{ | ||
// Pass in the list of app ids to get the final list of principals | ||
var principals = pnpContext.GetSiteCollectionManager().GetTenantACSPrincipals(legacyServicePrincipals, vanityUrlOptions); | ||
WriteObject(principals, true); | ||
} | ||
} | ||
|
||
else if (Scope == AzureACSPrincipalScope.All) | ||
{ | ||
var legacyServicePrincipals = pnpContext.GetSiteCollectionManager().GetLegacyServicePrincipals(); | ||
if (legacyServicePrincipals != null) | ||
{ | ||
// Pass in the list of app ids to get the final list of principals | ||
var principals = pnpContext.GetSiteCollectionManager().GetTenantAndSiteCollectionACSPrincipals(legacyServicePrincipals, IncludeSubsites, vanityUrlOptions); | ||
WriteObject(principals, true); | ||
} | ||
} | ||
else | ||
{ | ||
var principals = pnpContext.GetSiteCollectionManager().GetSiteCollectionACSPrincipals(IncludeSubsites, vanityUrlOptions); | ||
WriteObject(principals, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using PnP.Core.Services; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using PnP.Core.Admin.Model.SharePoint; | ||
using System; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using PnP.PowerShell.Commands.Base; | ||
using Microsoft.SharePoint.Client; | ||
|
||
namespace PnP.PowerShell.Commands.Apps | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPSharePointAddIn")] | ||
[OutputType(typeof(List<ISharePointAddIn>))] | ||
public class GetSharePointAddIn : PnPAdminCmdlet | ||
{ | ||
[Parameter(Mandatory = false)] | ||
public SwitchParameter IncludeSubsites; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var tenantAdminSiteUrl = Connection.TenantAdminUrl ?? UrlUtilities.GetTenantAdministrationUrl(ClientContext.Url); | ||
|
||
VanityUrlOptions vanityUrlOptions = new() | ||
{ | ||
AdminCenterUri = new Uri(tenantAdminSiteUrl) | ||
}; | ||
|
||
using var context = ClientContext.Clone(Connection.Url); | ||
|
||
// need to retrieve PnPContext for the connected site not the admin site | ||
using var pnpContext = Framework.PnPCoreSdk.Instance.GetPnPContext(context); | ||
|
||
List<ISharePointAddIn> addIns = pnpContext.GetSiteCollectionManager().GetSiteCollectionSharePointAddIns(IncludeSubsites, vanityUrlOptions); | ||
WriteObject(addIns, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace PnP.PowerShell.Commands.Enums | ||
{ | ||
/// <summary> | ||
/// Possible scopes to retrieve ACS Principals of | ||
/// </summary> | ||
public enum AzureACSPrincipalScope | ||
{ | ||
/// <summary> | ||
/// Retrieves the list scoped Azure ACS principal | ||
/// </summary> | ||
List, | ||
/// <summary> | ||
/// Retrieves the web scoped Azure ACS principal | ||
/// </summary> | ||
Web, | ||
/// <summary> | ||
/// Retrieves the site collection scoped Azure ACS principal | ||
/// </summary> | ||
Site, | ||
/// <summary> | ||
/// Retrieves the Tenant scoped Azure ACS principal | ||
/// </summary> | ||
Tenant, | ||
/// <summary> | ||
/// Retrieves the all Azure ACS principals | ||
/// </summary> | ||
All | ||
} | ||
} |