Win OS RecycleBin – Access via Powershell

Background

Over the Thanksgiving weekend spent time tackling a couple of machines that were running low on storage.

There are so many ways that one can lose space in MS Windows.

And, so we look between the white spaces.

in the past

  1. Recycle Bin Emptying Using Powershell
    Link

Recycle Bin

For those who want to programmatically look and repair, here is a bit of code to look in the Recycle Bin.

Code


Set-StrictMode -Version 2

$userRecycleBin_ID = 0x0a

Function Get-RecycleBin
{

	# Instanciate Shell Application
  	$objShell = New-Object -ComObject Shell.Application;

	#Get Recycle Bin
	$objShellRecycleBin = $objShell.NameSpace($userRecycleBin_ID)

	#Get Recycle Bin Items
	$objItems = $objShellRecycleBin.Items();

	#Get Recycle Bin Items
	#Only interested in explicitly listed attributes
	#$objItems | Select-Object * | Out-GridView -Wait
	$objItems | Select-Object Path, Name, IsFolder, Type, Size | Out-GridView -Wait

	return ( $objItems );

}

Function Stat-RecycleBin
{
	$objShell = New-Object -ComObject Shell.Application;

	$objItems = $objShell.NameSpace($userRecycleBin_ID).Items();

	#| measure
	$lNumberofEntries = $objItems.Count

	return ( $lNumberofEntries);

}

$objItems = Get-RecycleBin

$lNumberofEntries = $objItems.Count

$log = "Number of entries in reccyle bin {0}" -f $lNumberofEntries

Write-Host $log

Invoke


powershell  -noprofile -executionpolicy bypass -file ./recycleBinBrowse.ps1

Dedicated

As always most of this is somebody else.

He wrote it in two lines.

There were things I was missing and so I had to break it into single statements.

If you find find yourself having to do so same, don’t feel bad nor lonesome for the handicap.

 

Referenced Work

  1. Windows Dev Center
    • Docs > WindowsDesktop > The Windows Shell > Shell Reference > Shell Objects for Scripting and Microsoft Visual Basic > Shell > NameSpace
      • Shell.NameSpace method
        Link
    • Docs / Windows / Desktop / API / The Windows Shell / Shldisp.h / ShellSpecialFolderConstants enumeration
      • ShellSpecialFolderConstants Enumeration
        Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s