Get-SPRecycleBinStats

function Get-SPRecycleBinStats {

    param(
        $url
    )

        [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

        $SPSite = New-Object microsoft.SharePoint.SPSite($url)

        $RecycleBinStats =  New-Object System.Object
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name url -Value $url
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name RecycleBinEnabled -Value $false
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name RecycleBinCleanupEnabled -Value $false
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name RecycleBinRetentionPeriod -Value 0
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name SecondStageRecycleBinQuota -Value 0
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name FirstStageRecycleBinTotalItems -Value 0
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name FirstStageRecycleBinTotalSize -Value 0
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name SecondStageRecycleBinTotalItems -Value 0
        $RecycleBinStats | Add-Member -MemberType NoteProperty -Name SecondStageRecycleBinTotalSize -Value 0

        foreach ($SPRecycleBinItem in $SPSite.RecycleBin) {

            switch ($SPRecycleBinItem.ItemState) {

                FirstStageRecycleBin {
                    $RecycleBinStats.FirstStageRecycleBinTotalItems ++
                    $RecycleBinStats.FirstStageRecycleBinTotalSize += $SPRecycleBinItem.size
                }
                SecondStageRecycleBin {
                    $RecycleBinStats.SecondStageRecycleBinTotalItems ++
                    $RecycleBinStats.SecondStageRecycleBinTotalSize += $SPRecycleBinItem.size
                }
            }
        }

        $RecycleBinStats.RecycleBinCleanupEnabled = $spsite.WebApplication.RecycleBinCleanupEnabled
        $RecycleBinStats.RecycleBinEnabled = $spsite.WebApplication.RecycleBinEnabled
        $RecycleBinStats.SecondStageRecycleBinQuota = $spsite.WebApplication.SecondStageRecycleBinQuota
        $RecycleBinStats.RecycleBinRetentionPeriod = $spsite.WebApplication.RecycleBinRetentionPeriod

        $SPSite.Dispose()

        $RecycleBinStats

}

Get-SPRecycleBinStats -url "http://yoururlgoeshere"        

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s