GetxSPORecycleBinItem.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID b14c62c6-7eca-4fc5-b5c9-325b2879f7fc
 
.AUTHOR Chendrayan Venkatesan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS SharePointOnline,PowerShell
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Retrieves SharePoint Site Recyclebin Item
 
#>
 
    <#param
    (
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        $Url,
 
        [Parameter(Mandatory)]
        [System.Management.Automation.CredentialAttribute()]
        [pscredential]
        $Credential
    )#>



Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'
function Get-xSPOSiteRecycleBinItem
{
<#
.SYNOPSIS
    Get-xSPOSiteRecycleBinItem is to retrieve recyle bin items from the given SharePoint site
.DESCRIPTION
    This cmdlet is to retrieve all the SharePoint recyle bin items and allows us to choose the required properties.
.EXAMPLE
    C:\PS> Get-xSPOSiteRecycleBinItem -Url https://contoso.sharepoint.com -Credential "Admin@contoso.onmicrosoft.com"
    Shows all the properties
.EXAMPLE
    C:\PS> Get-xSPOSiteRecycleBinItem -Url https://contoso.sharepoint.com -Credential "Admin@contoso.onmicrosoft.com" | Select Title , Size
    Retrieves Title and Size of the item (Choose the properties required by pressing <Tab> , <Tab>)
.LINK
    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.recyclebinitem.aspx
.NOTES
    Read the MSDN Documentation by executing "help New-SPOList -Online"
#>

    [OutPutType('Microsoft.SharePoint.Client.RecycleBinItem')]
    param
    (
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        $Url,

        [Parameter(Mandatory)]
        [System.Management.Automation.CredentialAttribute()]
        [pscredential]
        $Credential        
    )
    process
    {
       
        try 
        {
            $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url)
            $SPOClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Credential.UserName,$Credential.Password)
            $Site = $SPOClientContext.Site
            $SPOClientContext.Load($Site)
            $RecycleBinItemCollection = $Site.RecycleBin
            $SPOClientContext.Load($RecycleBinItemCollection)
            $SPOClientContext.ExecuteQuery()
            $SPOClientContext.Dispose()
            foreach($RecycleBinItem in $RecycleBinItemCollection)
            {
                $RecycleBinItem
            }
        }
        catch 
        {
            $_.Exception.Message
        }
    }
}