[PowerShell] / Remove-Item-Secure.ps1 Repository:
ViewVC logotype

View of /Remove-Item-Secure.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (download) (annotate)
Tue Apr 22 02:27:57 2014 UTC (6 years, 7 months ago) by ian
File size: 1479 byte(s)
Initial import of Remove-Item-Secure.ps1: new script to secure erase files;
Fixes Get-LenovoProductInfo.ps1 which broke when Lenovo added a captcha;
New query URL for Get-LenovoProductInfo.ps1 provides warranty and part data from a single web request instead of one each;
<#

.NOTES
 Written by Ian Cammarata  http://ian.cammarata.us
 Remove-Item-Secure

To Do:
 -Lots of stuff

.SYNOPSIS
Secure erase files.


.EXAMPLE
PS> 

#>

<#
mkdir secure-erase-test
mkdir secure-erase-test/test
Set-Content "secure-erase-test/ing.txt" "asdf"
Set-Content "secure-erase-test/test/ing.txt" "asdf"
Copy-Item tmp/*.jpg secure-erase-test/test/
explorer.exe (Join-Path (pwd) "secure-erase-test/test/")
#>

[cmdletbinding( SupportsShouldProcess = $True )]
param(
    #File system object to secure erase.
    [Parameter( Mandatory = $True, Position = 0, ValueFromPipeline= $True )]
    [Alias( "Files" )]
    [String[]]
    $Path
)


#BEGIN {  
#}

PROCESS {
    Foreach ( $item in $Path ) {
        $branches = Get-ChildItem $item -Recurse | ? { $_.PSIsContainer }
        $leaves = Get-ChildItem $item -Recurse | ? { $_.PSIsContainer -eq $False }

        "Burning leaves..."
        Foreach ( $leaf in $leaves ) {
            if ( $psCmdlet.ShouldProcess( $leaf, "Secure Erase" ) ) {
                Set-Content $leaf ("0" * $tmp[1].Length)
                $leaf.MoveTo( ( Join-Path $leaf.Directory ( Get-Random ) ) )
                $leaf.Delete()
            }
        }

        "Chopping branches..."
        Foreach ( $branch in $branches ) {
            $branch.MoveTo( ( ( Join-Path $branch.PSParentPath ( Get-Random ) ) -split "::" )[1] )
        }
        Remove-Item $Path -Recurse -Force
    }
}

Contact
ViewVC Help
Powered by ViewVC 1.0.4