sharepoint powershell online get-pnprecyclebinitems access denied RRS feed

  • Question

  • Hi all!

    I need to get count of Sharepoint Online recycle bin. I'm a site collection administrator on site collection that I work.

    I tried to run this script:

    Import-Module Microsoft.Online.SharePoint.PowerShell
    $User = ""
    $PWord = ConvertTo-SecureString -String "MyPass" -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    $SiteUrl = ""
    Connect-PnPOnline -Url $SiteUrl -Credentials $Credential
    $Web = Get-PnPWeb 

    And I get this error message:

    Get-PnPRecycleBinItem : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    At line:1 char:2
    + (Get-PnPRecycleBinItem).count
    +  ~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : WriteError: (:) [Get-PnPRecycleBinItem], ServerUnauthorizedAccessException
        + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.RecycleBin.GetRecycleBinItems

    How to solve this problem?

    Monday, July 12, 2021 10:43 AM