myusrn
myusrn

Reputation: 1110

powershell core 7.0.3 Az.Account PSADServicePrincipal appRoles and oauth2permissions

I have windows powershell 5.1 script block like the following that successfully retrieves appRoles and oauth2permissions.

import-module -name AzureAD
if ($null -eq $mycredentials) { $mycredentials = Get-Credential }
$azConnectionContext = Connect-AzureAD -Credential $mycredentials
# $svp = Get-AzureADServicePrincipal -Filter "DisplayName -eq 'Microsoft Graph' } # not working, why ???
$svp = Get-AzureADServicePrincipal -All $true | ? { $_.DisplayName -eq 'Microsoft Graph }
$appRoles = $svp.AppRoles; $oauth2permissions = $svp.Oauth2Permissions

I'm trying to convert to powershell core 7 script block like the following and i'm unable to retrive appRoles and oauth2permissions because the PSADServicePrincipal type doesn't expose those properties.

import-module -name Az.Accounts
$azConnectionContext = Connect-AzAccount 
$svp = Get-AzADServicePrincipal -DisplayName 'Microsoft Graph' }
$appRoles = $svp.AppRoles; $oauth2permissions = $svp.Oauth2Permissions  # both of these fail

Question - anyone know how i get at azure ad service principal appRoles and oauth2permissions using powershell core 7.0.3 apis and types?

Upvotes: 0

Views: 406

Answers (2)

Andrew Stein
Andrew Stein

Reputation: 11

To your last question, remove-module only removes a module for the current session. You need to run Uninstall-Module instead.

There is an Uninstall-AzModule function here that might help you: https://learn.microsoft.com/en-us/powershell/azure/uninstall-az-ps?view=azps-4.6.1

Upvotes: 1

AlfredoRevilla-MSFT
AlfredoRevilla-MSFT

Reputation: 3485

Instead of:
$svp.AppRoles;

Use:
$svp.AppRole;

$svp.Oauth2Permissions should work. Type should be Microsoft.Azure.PowerShell.Cmdlets.Resources.Models.Api16.OAuth2Permission.

Upvotes: 2

Related Questions