diff --git a/documentation/Get-PnPPowerAppPermissionList.md b/documentation/Get-PnPPowerAppPermissionList.md new file mode 100644 index 000000000..2f5f59747 --- /dev/null +++ b/documentation/Get-PnPPowerAppPermissionList.md @@ -0,0 +1,134 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPPowerAppPermissions.html +external help file: PnP.PowerShell.dll-Help.xml +title: Get-PnPPowerAppPermissions +--- + +# Get-PnPPowerAppPermissions + +## SYNOPSIS + +**Required Permissions** + +* Azure: management.azure.com +* PowerApps: service.powerapps.com + +Returns the list of permissions assigned to a specified Power App. + +## SYNTAX + +```powershell +Get-PnPPowerAppPermissions [-Environment ] [-AsAdmin] -Identity +[-Connection ] [-Verbose] +``` + +## DESCRIPTION + +This cmdlet returns the list of user or group permissions granted to a specific Power App. + +## EXAMPLES + +### Example 1 + +```powershell +Get-PnPPowerAppPermissions -Identity "bde2239e-fabc-42ad-9c9e-72323413b1b0" +``` + +Returns the list of permissions for the specified Power App in the default environment. + +### Example 2 + +```powershell +Get-PnPPowerAppPermissions -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity "bde2239e-fabc-42ad-9c9e-72323413b1b0" -AsAdmin +``` + +Returns the list of permissions for the specified Power App in the given environment using admin context. + +## PARAMETERS + +### -Environment + +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. + +```yaml +Type: PowerPlatformEnvironmentPipeBind +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: The default environment +Accept pipeline input: True +Accept wildcard characters: False +``` + +### -AsAdmin + +If specified, returns permissions using admin privileges. If not specified, only permissions for the current user will be returned. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity + +The ID of the Power App to retrieve permissions for. + +```yaml +Type: PowerAppPipeBind +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -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) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Verbose + +When provided, additional debug statements will be shown while executing the cmdlet. + +```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) diff --git a/src/ALC/PnP.PowerShell.ALC.csproj b/src/ALC/PnP.PowerShell.ALC.csproj index a6f03847b..947720665 100644 --- a/src/ALC/PnP.PowerShell.ALC.csproj +++ b/src/ALC/PnP.PowerShell.ALC.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissions.cs b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissions.cs new file mode 100644 index 000000000..33e145004 --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissions.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp +{ + public class PowerAppPermissions + { + public List value { get; set; } + } +} + diff --git a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsPrincipal.cs b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsPrincipal.cs new file mode 100644 index 000000000..c3d71f722 --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsPrincipal.cs @@ -0,0 +1,14 @@ + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp +{ + public class PowerAppPermissionsPrincipal + { + public string id { get; set; } + public string displayName { get; set; } + public string email { get; set; } + public string type { get; set; } + public string tenantId { get; set; } + public string preferredLanguage { get; set; } + } + +} \ No newline at end of file diff --git a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsProperties.cs b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsProperties.cs new file mode 100644 index 000000000..e5270496a --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsProperties.cs @@ -0,0 +1,16 @@ +using System; + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp +{ + public class PowerAppPermissionsProperties + { + public string roleName { get; set; } + public PowerAppPermissionsPrincipal principal { get; set; } + public string scope { get; set; } + public string notifyShareTargetOption { get; set; } + public bool inviteGuestToTenant { get; set; } + public DateTime createdOn { get; set; } + public string createdBy { get; set; } + } + +} \ No newline at end of file diff --git a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsValue.cs b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsValue.cs new file mode 100644 index 000000000..eac5eb4ed --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppPermissionsValue.cs @@ -0,0 +1,12 @@ + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp +{ + public class PowerAppPermissionsValue + { + public string name { get; set; } + public string id { get; set; } + public string type { get; set; } + public PowerAppPermissionsProperties properties { get; set; } + } + +} \ No newline at end of file diff --git a/src/Commands/PowerPlatform/PowerApps/GetPowerAppPermissions.cs b/src/Commands/PowerPlatform/PowerApps/GetPowerAppPermissions.cs new file mode 100644 index 000000000..5b9276c90 --- /dev/null +++ b/src/Commands/PowerPlatform/PowerApps/GetPowerAppPermissions.cs @@ -0,0 +1,59 @@ +using PnP.PowerShell.Commands.Base; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Utilities; +using System; +using System.Linq; +using System.Management.Automation; +using System.Text.Json; + +namespace PnP.PowerShell.Commands.PowerPlatform.PowerApps +{ + [Cmdlet(VerbsCommon.Get, "PnPPowerAppPermissions")] + [OutputType(typeof(Model.PowerPlatform.PowerApp.PowerApp))] + public class GetPowerAppPermissions : PnPAzureManagementApiCmdlet + { + [Parameter(Mandatory = false, ValueFromPipeline = true)] + public PowerPlatformEnvironmentPipeBind Environment; + + [Parameter(Mandatory = false)] + public SwitchParameter AsAdmin; + + [Parameter(Mandatory = true)] + public PowerAppPipeBind Identity; + + protected override void ExecuteCmdlet() + { + string environmentName = null; + string powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); + if (ParameterSpecified(nameof(Environment))) + { + environmentName = Environment.GetName(); + + WriteVerbose($"Using environment as provided '{environmentName}'"); + } + else + { + environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(ArmRequestHelper, Connection.AzureEnvironment)?.Name; + + if (string.IsNullOrEmpty(environmentName)) + { + throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); + } + + WriteVerbose($"Using default environment as retrieved '{environmentName}'"); + } + + if (ParameterSpecified(nameof(Identity))) + { + var appName = Identity.GetName(); + + WriteVerbose($"Retrieving specific PowerApp permissions with the provided name '{appName}' within the environment '{environmentName}'"); + + var result = PowerAppsRequestHelper.GetResultCollection($"{powerAppsUrl}/providers/Microsoft.PowerApps{(AsAdmin ? "/scopes/admin/environments/" + environmentName : "")}/apps/{appName}/permissions?api-version=2022-11-01"); + + WriteObject(result, true); + } + + } + } +} \ No newline at end of file