Deleting Folder Contents with Powershell


Here a few methods of deleting the contents of folders with Powershell. These methods are useful for keeping servers clean and tidy and emptying users recycle bins.

Clear out users recycle bin data based on SID
Import-Module activedirectory

[string]$recycleBinPath = ‘C:\$Recycle.Bin\’
$userSID = ((Get-ADUser chrisa).sid).value
Remove-Item “$recycleBinPath$userSID” -recurse -force

Delete all folders in $Recycle.bin
dir ‘c:\$recycle.bin’ -force|foreach{if($_.name -like “s-*”){rd $_.name -force -recurse}}

Hope these help

No comments yet... Be the first to leave a reply!

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 )

Connecting to %s

%d bloggers like this: