Last active
January 23, 2021 17:38
-
-
Save gautamdsheth/0fb8fff1fe3fdcc8dca34e24cdd65889 to your computer and use it in GitHub Desktop.
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
$PnPPowerShellAppId = "31359c7f-bd7e-475c-86db-fdb8c937548e" | |
# Connect to you Azure AD, use Global admin or equivalent account | |
Connect-AzAccount | |
# get graph access token for current user --need Global admin | |
$accessTokenInformation = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com" | |
$token = $accessTokenInformation.Token | |
# Create a new service prinicpal | |
$pnpServicePrincipal = New-AzADServicePrincipal -ApplicationId $PnPPowerShellAppId | |
# 00000003-0000-0ff1-ce00-000000000000 is the well know application id for SharePoint's service prinicpal | |
$spServicePrincipal = Get-AzADServicePrincipal -ApplicationId "00000003-0000-0ff1-ce00-000000000000" | |
# pass the necessary permissions that you need | |
$requestedScopes = "User.ReadWrite.All AllSites.FullControl TermStore.ReadWrite.All" | |
$payload = @{ | |
clientId = $pnpServicePrincipal.Id | |
consentType = "AllPrincipals" | |
principalId = $null | |
resourceId = $spServicePrincipal.Id | |
scope = $requestedScopes | |
} | ConvertTo-Json | |
# Assign and grant permissions | |
Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants" -Headers @{Authorization = "Bearer $token"} | |
-Body $payload -Method "POST" -ContentType "application/json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment