Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Remove-PnPAzureADServicePrincipalAssignedAppRole -Principal <ServicePrincipalPip

### By app role name
```powershell
Remove-PnPAzureADServicePrincipalAssignedAppRole -Principal <ServicePrincipalPipeBind> -AppRoleName <String> [-Connection <PnPConnection>]
Remove-PnPAzureADServicePrincipalAssignedAppRole -Principal <ServicePrincipalPipeBind> -AppRoleName <String> [-BuiltInType <ServicePrincipalBuiltInType>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand Down Expand Up @@ -76,6 +76,15 @@ Get-PnPAzureADServicePrincipal -AppId fd885e69-86dc-4f3b-851e-ad04920031cf | Rem

Removes all app roles from the application registration with the app Id/Client Id fd885e69-86dc-4f3b-851e-ad04920031cf

### EXAMPLE 6

```powershell
Remove-PnPAzureADServicePrincipalAssignedAppRole -Principal "My application" -AppRoleName "Sites.FullControl.All" -BuiltInType SharePointOnline
```

Removes the "Sites.FullControl.All" app role assignment only from the SharePointOnline for the application registration named "My application".


## PARAMETERS

### -Principal
Expand Down Expand Up @@ -120,6 +129,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -BuiltInType
The built in application type to use for the app role. This can be MicrosoftGraph or SharePointOnline.

```yaml
Type: ServicePrincipalBuiltInType
Parameter Sets: By app role name

Required: False
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.

Expand Down
25 changes: 23 additions & 2 deletions src/Commands/Apps/RemoveAzureADServicePrincipalAssignedAppRole.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Enums;
using PnP.PowerShell.Commands.Model.AzureAD;
using PnP.PowerShell.Commands.Utilities;
using System.Collections.Generic;
Expand All @@ -27,7 +29,11 @@ public class RemoveAzureADServicePrincipalAssignedAppRole : PnPGraphCmdlet
public ServicePrincipalAssignedAppRoleBind Identity;

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_BYAPPROLENAME)]
public string AppRoleName;
[ValidateNotNull]
public ServicePrincipalAvailableAppRoleBind AppRoleName;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_BYAPPROLENAME)]
public ServicePrincipalBuiltInType BuiltInType;

protected override void ExecuteCmdlet()
{
Expand Down Expand Up @@ -56,7 +62,22 @@ protected override void ExecuteCmdlet()
}
else
{
ServicePrincipalUtility.RemoveServicePrincipalRoleAssignment(GraphRequestHelper, principal, AppRoleName);
if (!ParameterSpecified(nameof(BuiltInType)))
{
ServicePrincipalUtility.RemoveServicePrincipalRoleAssignment(GraphRequestHelper, principal, AppRoleName.ToString());
}
else
{
var resource = ServicePrincipalUtility.GetServicePrincipalByBuiltInType(GraphRequestHelper, BuiltInType);
AzureADServicePrincipalAppRole appRole = AppRoleName.GetAvailableAppRole(Connection, AccessToken, resource);

if (appRole == null)
{
throw new PSArgumentException("AppRole not found", nameof(AppRoleName));
}
LogDebug($"Removing app role {appRole.Value}: {appRole.DisplayName}");
ServicePrincipalUtility.RemoveServicePrincipalRoleAssignment(GraphRequestHelper, principal, appRole);
}
}
}
else
Expand Down
Loading