Safely Deleting Data

To safely delete files, folders, or entire drives, PowerShell can use the built-in cipher.exe tool. This line would safely delete the old user profile:

Cipher.exe /w:c:\Users\ObsoleteUser

Note that the path to the folder to delete needs to be separated by a *** from the parameter /w. Clearing the data takes a while: Windows is overwriting the entire data content multiple times to ensure it cannot be recovered.

Twitter This Tip! ReTweet this Tip!

  • Note:

    Of course this can be done for not only files, but whole directories/tree and a whole drive. This exe will perform 3 passes, so as notes, be patient.

    The more you go after the more minutes / hours it will take.

    A large drive will Take a day or two to complete. A single file will take a few minutes to complete.

    Before you ask, no there is no way to speed it up. Drive speed is a sticking point as well as other stuff running on the system.

    Yes, you can use your system while it is running or target files and folders, but there is a performance penalty.

    So, best to do this when you have no plans to use your system for a while.

    For easy recall / use. Use a function and put in your profile or dot source.

    Function Start-DataWipe ($PathToTarget)

    { Cipher.exe "/w:$PathToTarget" }

    Start-DataWipe -PathToPathToTarget 'C:\TestFolder\WipeMe.txt'

    # results

    To remove as much data as possible, please close all other applications while

    running CIPHER /W.

    Writing 0x00

    .....................................................................................................................

    Writing 0xFF

    .....................................................................................................................

    Writing Random Numbers

    ........................................................................................................................

    # or

    Start-DataWipe -PathToPathToTarget 'C:\TestFolder'

    # or

    Start-DataWipe -PathToPathToTarget 'j:'

    I marry this up with fdisk when I am planning to repurpose a drive to another computer or other.

    Well, that is when I do not have a drive degausser available for use.

  • Thanks for your sharing... I have questions :1. This is just used for HDD, but not for SSD right? 2.it is only used to clear the spare space of Disk. It can't delete the files which saved in the path. right?

  • With the exception of a couple of systems, all my drives are SSD, standard versions and PCI NVMe and I do use it on those drives as well (heck I've even done this on USB sticks), but you must keep in mind that specifics of SSD endurance as detailed here:

    'storagesearch.com/ssdmyths-endurance.html' and on many drive hardware vendor sites.

    Though this is a decent tool. You really have to have a reason to use it. In most cases, well, if it is just drives for your onw use,  delete is fine. If you are giving the drive away, or using it in another system you do not own, then this is a good thing to use.

    So, the decision is this a destructive and throw away or a clean and recuse.

    The details of cipher.exe are on the MS web sites, but all it does is overwrite the location to make anything unrecoverable. The process marks those drive sectors as available for new data. This last part is really not much different than format. Format really does not delete every sector, just marks as available for the OS to write over. Here the reason you can use tools to recovers deleted data / formatted hard drives.

    The cipher, deal is completely overwriting the sectors with gibberish. So, yes, with the right tools and time, you could recover the gibberish, but not the original data.

    Again for this just a software way of degaussing a drive, but if you want the real deal. Get an inexpensive degausser. They range between $150 to several thousands of dollars. This things though are truly for destruction, not reuse efforts. If it is just destruction, take a cheaper route, and use an ax to the drive, thermite it or take to a shredding location.

    If you are just reusing in you personal systems, cipher / fdisk / full format (and be aware this steps together takes a really long time - days actually). Yet, again, for SSD, that whole durance thing (drive lifetime) needs to be top of mind.

  • ,Thanks, good to know all the info and knowledge.