none
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 = "nikita.murashkin@contoso.com"
    $PWord = ConvertTo-SecureString -String "MyPass" -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    $SiteUrl = "https://contoso.sharepoint.com/sites/contoso"
    Connect-PnPOnline -Url $SiteUrl -Credentials $Credential
    $Web = Get-PnPWeb 
    $Web.Title
    (Get-PnPRecycleBinItem).count

    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

All replies

  • You may need additional roles.  If you are the site Admin, there should not be a permissions issue, but perhaps it is the Directory you are in.  what happens when you run the command alone??

    I found this quoted direct from MS

    "This command will return all the items in the recycle bin for the SharePoint site you connected to with Connect-PnPOnline. You must connect as a Site Collection Owner or Administrator. The SharePoint Admin Role in the tenant alone will not work. If you are not a Site Collection Admin connect to the Tenant Admin URL with Connect-PnPOnline and use Get-PnPTenantRecycleBinItem."


    BlankMonkey

    • Proposed as answer by Scuba_Duba Thursday, March 3, 2022 8:35 PM
    Thursday, February 17, 2022 8:52 PM
  • I don't know about this anything , any suggestions ?
    Tuesday, February 22, 2022 11:39 AM
  • Hi, I think you should get the return object from Connect-PnPOnline and use it for the -Connection Get-PnPRecycleBinItem parameter:
    $conn=Connect-PnPOnline -Url $SiteUrl -Credentials $Credential
    $Web = Get-PnPWeb
    $ WebTitle
    (Get-PnPRecycleBinItem -Connection $conn).Count
    Wednesday, March 2, 2022 7:56 AM
  • Tnx!
    Wednesday, March 2, 2022 9:08 AM
  • Thanks for the solution.
    Saturday, March 5, 2022 8:04 AM
  • Solution:
    This error is connected with the Custom Script settings in the SharePoint admin center. Running custom script allows users to customize SharePoint sites. By default, custom script is allowed only on sites created by SharePoint admins but blocked on sites created by users, on OneDrive sites, and on the root site collection. If custom script is blocked, it prevents CodeTwo Backup from restoring the backed-up content.

    To fix this error, you need to allow custom script on a particular site to which you are restoring your backed-up data. For OneDrive sites (personal sites), you only need to enable custom script globally in the SharePoint admin center. For other sites (team sites and site collections), you need to change the Custom Script settings in the SharePoint admin center as well as enable custom script for individual sites by using SharePoint Online Management Shell.

    Regards,

    Rachel Gomez

    Saturday, September 24, 2022 5:27 AM