Get-PnPTenantSite: Attempted to perform an unauthorized operation.

Edward Croxton 0 Reputation points
2024-11-06T14:48:27.3966667+00:00

How to I get around this error.

Tying to Get All Site collections data and export to CSV file

Get-PnPTenantSite: Attempted to perform an unauthorized operation.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,067 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yanli Jiang - MSFT 27,161 Reputation points Microsoft Vendor
    2024-11-07T02:46:20.8566667+00:00

    Hi @Edward Croxton ,

    Welcome to Q&A forum!

    It looks like the account doesn't have enough permission.

    Here are a few steps you can try to resolve this error:

    Check Permissions: Ensure that the account you're using has the necessary permissions. For Get-PnPTenantSite, you typically need SharePoint Online Administrator or Global Administrator permissions.

    1. Update PnP PowerShell Module: Make sure you're using the latest version of the PnP PowerShell module. You can update it using:
         Update-Module -Name PnP.PowerShell
      
      Connect with Correct Permissions: When connecting to SharePoint Online, ensure you're using the correct permissions. For example:
         Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -ClientId "your-client-id" -ClientSecret "your-client-secret"
      
    2. Use Managed Identity: If you're using Azure Automation or a similar service, ensure that the managed identity has the necessary permissions. You might need to grant Sites.FullControl.All permissions instead of more limited ones
    3. Check for Known Issues: Sometimes, there might be known issues or bugs with specific versions of the PnP PowerShell module. Checking the PnP PowerShell GitHub repository for similar issues can be helpful.

    If these steps don't resolve the issue, it may to be caused by PnP PowerShell. According to my search, there are many users who have encountered this problem. As currently we only support general issues of SharePoint, so we recommend you submit a new issue on github. There are concentrated discussions on issues related to PnP PowerShell.

    Good day!


    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.