Replies: 5 comments 2 replies
-
What works for me: $resourceURI ="https://<yourtenant>.sharepoint.com"
$siteUrl="https://<yourtenant>.sharepoint.com/sites/<yoursite>"
# Get token
$tokenAuthURI = $env:IDENTITY_ENDPOINT + "?resource=$resourceURI&api-version=2017-09-01"
$tokenResponse = Invoke-RestMethod -Method Get -Headers @{"Secret" = "$env:IDENTITY_HEADER" } -Uri $tokenAuthURI
$accessToken = $tokenResponse.access_token
# Authenticate to SPO site
Connect-PnPOnline -Url $siteUrl -AccessToken $accessToken
Get-PnPSite
|
Beta Was this translation helpful? Give feedback.
-
We are having the same problem. (Note that kkazala's suggestion doesn't help -- we are trying to use ManagedIdentity, which is a different way of authentication from using the AccessToken. Not using the ManagedIdentity at all, is not a way to make using the ManagedIdentity work.) I want to connect using the Managed Identity, then use PNP cmdlets on Sharepoint content. Has anyone had success using the -ManagedIdentity? $Conn = Connect-PnPOnline -ManagedIdentity $Conn = Connect-PnPOnline -ManagedIdentity -URL $SiteURL $Conn = Connect-PnPOnline -ManagedIdentity -ReturnConnection $true |
Beta Was this translation helpful? Give feedback.
-
@kkazala we want to use the -ManagedIdentity parameter, not the -AccessToken parameter. If it turns out that ManagedIdentity doesn't work in the current release, we will give your work-around a try! Thanks. |
Beta Was this translation helpful? Give feedback.
-
no update on this, i am also experiencing the same issue and are trying to use the managed identity? |
Beta Was this translation helpful? Give feedback.
-
Same behaviour. I'm using app registration with cert path and running my code in Azure Pipeline. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an Azure Runbook with a system managed identity. I'm using the following code as a simple test:
The "Connect-PnPOnline -ManagedIdentity" works fine and connects. However, the next line, "Get-PnPTenantSite -IncludeOneDriveSites" returns the following error:
"The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect."
If I switch the runbook back to using a "runas" account, it works fine.
If I try and use "Connect-PnPOnline -ManagedIdentity -Url $url" it complains that there are too many arguments in the command. Is there something different I need to do with using a managed identity?
Beta Was this translation helpful? Give feedback.
All reactions