Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
M365.TeamsBackup/deploy/create-aadapp-cli.ps1
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 lines (25 sloc)
1.57 KB
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
# Azure CLI must be installed | |
# https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli | |
# User must be able to create apps and consent (Global Admin, ...) | |
$appName = "dev-GKMM-msteamsbackup-app"; #Change for example GKMM to your tenant | |
$servicePrincipalName = "Microsoft Graph"; | |
$servicePrincipalNameOauth2Permissions = @("Channel.ReadBasic.All", "ChannelMember.Read.All", "ChannelMessage.Read.All", "ChannelSettings.Read.All", "Group.Read.All", "GroupMember.Read.All", "Team.ReadBasic.All", "TeamMember.Read.All", "TeamSettings.Read.All", "TeamsTab.Read.All"); | |
az login --use-device-code --allow-no-subscriptions | |
$servicePrincipalId = az ad sp list --filter "displayname eq '$servicePrincipalName'" --query '[0].appId' | ConvertFrom-Json | |
$reqGraph = @{ | |
resourceAppId = $servicePrincipalId | |
resourceAccess = @() | |
} | |
(az ad sp show --id $servicePrincipalId --query oauth2Permissions | ConvertFrom-Json) | Where-Object { $_.value -in $servicePrincipalNameOauth2Permissions} | ForEach-Object { | |
$permission = $_ | |
$delPermission = @{ | |
id = $permission.Id | |
type = "Scope" | |
} | |
$reqGraph.resourceAccess += $delPermission | |
} | |
Set-Content ./required_resource_accesses.json -Value ("[" + ($reqGraph | ConvertTo-Json) + "]") | |
$newapp = az ad app create --display-name $appName --available-to-other-tenants false --native-app true --required-resource-accesses `@required_resource_accesses.json | ConvertFrom-Json | |
az ad app permission admin-consent --id $newapp.appId | |
"ClientId: " + $newapp.appId; | |
"TenantId: " + (az account show | ConvertFrom-Json).tenantId; |