PoshCode Archive  Artifact [b9428f8d2d]

Artifact b9428f8d2de44c99e308f3686ccc4f650d23ffcf9f4dfb5a37c077619fd00b4d:

  • File Remove-Trash.ps1 — part of check-in [e0ef1ac06e] at 2018-06-10 13:58:44 on branch trunk — A simple script cmdlet that allows you to empty your recycle bin. (user: Mark Schill size: 1208)

# 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)
}