# encoding: ascii
# api: csharp
# title: Remove-Trash
# description: A simple script cmdlet that allows you to empty your recycle bin.
# version: 0.1
# type: class
# author: Mark Schill
# license: CC0
# x-poshcode-id: 566
# x-archived: 2016-03-17T00:58:06
# x-published: 2009-09-03T15:56:00
#
#
#requires -version 2.0
add-type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace recyclebin
{
public class Empty
{
[DllImport("shell32.dll")]
static extern int SHEmptyRecycleBin(IntPtr hWnd, string pszRootPath, uint dwFlags);
public static void EmptyTrash(string RootDrive, uint Flags)
{
SHEmptyRecycleBin(IntPtr.Zero, RootDrive, Flags);
}
}
}
"@
cmdlet Remove-Trash -snapin CMSchill.RemoveTrash
{
param(
[Parameter(Position=0, Mandatory=$false)][string]$Drive = "",
[switch]$NoConfirmation,
[switch]$NoProgressGui,
[switch]$NoSound
)
[int]$Flags = 0
if ( $NoConfirmation ) { $Flags = $Flags -bor 1 }
if ( $NoProgressGui ) { $Flags = $Flags -bor 2 }
if ( $NoSound ) { $Flags = $Flags -bor 4 }
[recyclebin.Empty]::EmptyTrash($RootPath, $Flags)
}