Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 40 lines (39 sloc) 1.571 kb
388229d @sushihangover ...
authored
1 Function Clear-Trash {
2 <#
3 .NOTES
4 Copyright 2012 Robert Nees
5 Licensed under the Apache License, Version 2.0 (the "License");
6 http://sushihangover.blogspot.com
7 .SYNOPSIS
8 Clear/Empty the local or remote system trashcan
9 .DESCRIPTION
10 Deletes all the items in the local or remote system trashcan. If you need empty the
11 trash on a remote system, pass this script via the FilePath of Invoke-Command (see examples)
12 .EXAMPLE
13 Clear-Trash -whatif
14 What if: Performing "Remove File" in trashcan TTIDSDIEUIC.zip
15 What if: Performing "Remove File" in trashcan Veetle 1.1.5.ipa
16 What if: Performing "Remove File" in trashcan SoundHound 4.4.ipa
17 What if: Performing "Remove File" in trashcan Starbucks 2.1.2.ipa
18 .EXAMPLE
19 Clear-Trash
20 Permanently clear the trashcan contents
21 .EXAMPLE
22 Invoke-Command -filepath .\Clear-Trash.ps1 -ArgumentList $True -ComputerName (Get-ADComputers -Group 'PilotTesting')
23 See what would be deleted from trashcans of multiple remote computers
24 .LINK
25 http://sushihangover.blogspot.com
26 #>
27 param (
28 [parameter(Mandatory=$false,Position=0)][switch]$WhatIf
29 )
30 $objShell = New-Object -ComObject Shell.Application
31 $objFolder = $objShell.Namespace(0xA)
32 $objFolder.items() | ForEach-Object {
33 if (!$WhatIf) {
34 remove-item $_.path -Recurse -Confirm:$false
35 } else {
36 'What if: Performing "Remove File" in trashcan ' + $_.Name
37 }
38 }
39 }
Something went wrong with that request. Please try again.