Office 365: Cómo acceder a la papelera de reciclaje de un sitio de SPO con PowerShell!

En esta ocasión os comparto un script que permite acceder al contenido de la papelera de reciclaje de un sitio de SharePoint Online (SPO) por medio de PowerShell y haciendo uso del Modelo de Objetos en Cliente (CSOM). Podéis descargaros el script desde el siguiente enlace:How to get recycle bin items in a SharePoint Online Site

############################################################################################################################################

# Script that allows to get all the items in the recycle bin of a SPO Site.

# Required Parameters:

#  -> $sUserName: User Name to connect to the SharePoint Online Site.

#  -> $sPassword: Password for the user.

#  -> $sSiteUrl: SharePoint Online Site.

############################################################################################################################################

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that gets all the items in the recycle bin of a SPO Site.

function Get-ItemsSPOSiteRecycleBin

{

    param ($sSiteUrl,$sUserName,$sPassword,$sCSOMPath)

    try

    {    

        Write-Host "----------------------------------------------------------------------------"  -ForegroundColor Green

        Write-Host "Getting all items in the Recycle Bin of a SPO Site" -ForegroundColor Green

        Write-Host "----------------------------------------------------------------------------"  -ForegroundColor Green

     

        #Adding the Client OM Assemblies        

        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"        

        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"

                     

        Add-Type -Path $sCSOMPath         

        Add-Type -Path $sCSOMRuntimePath        

 

        #SPO Client Object Model Context

        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 

        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  

        $spoCtx.Credentials = $spoCredentials 

 

        #SPO Site

        $spoWeb = $spoCtx.Web

        #Recycle Bin Content for the user

        $spoRecycleBinItemCollection = $spoWeb.RecycleBin

        $spoCtx.Load($spoRecycleBinItemCollection)

        $spoCtx.ExecuteQuery()

        foreach($spoRecycleBinItem in $spoRecycleBinItemCollection){

            Write-Host "Item:" $spoRecycleBinItem.Title "- Deleted By:" $spoRecycleBinItem.DeletedByName "- Deleted Date:" $spoRecycleBinItem.DeletedDate

        }

        $spoCtx.Dispose()

    }

    catch [System.Exception]

    {

        write-host -f red $_.Exception.ToString()   

    }    

}

 

#Required Parameters

$sSiteUrl = "https://<SPO_Site>" 

$sUserName = "<SPOUser>@<O365DOmain>.onmicrosoft.com" 

#$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString  

$sPassword= ConvertTo-SecureString "<O365Password>" -AsPlainText -Force

$sCSOMPath="<CSOM_Path>"

 

Get-ItemsSPOSiteRecycleBin -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword -sCSOMPath $sCSOMPath

Y este es el resultado de la ejecución del script:

image