Hi,
I’m trying to find old files in several directories and want them to delete securely with sdelete utility.
Also, I want to log that sdelete activity and I noticed on the file on which I do not have permission I got an error:
SDelete is set for 3 passes. E:\DIR1\TEST\This_is_test_file.exe... Error opening E:\DIR1\TEST\This_is_test_file.exe for delete: Access is denied. No files/folders found that match E:\DIR1\TEST\This_is_test_file.exe.
But, in the sdelete.log I get an output:
---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- Beginning run at: 11/09/2018 14:58:55 Using shred command: C:\ADMIN\sdelete64.exe Shred iterations: -p 3 ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- Shredding file: E:\DIR1\TEST\This_is_test_file.exe C:\ADMIN\sdelete64.exe -p 3 E:\DIR1\TEST\This_is_test_file.exe Shred exited: True Shred return code: 0 Ending at: 11/09/2018 14:58:58 ----------------------------------------------------------------------------------------------
Can someone help me with capturing those files that actually not deleted and save it to another log file?
This is what I got so far:
$Now=Get-Date $Days="30" $Lastwrite = $Now.AddDays(-$Days) $dt = (get-date).ToString("ddMMyyyy") $CSVFile = 'E:\Log\ToDelete_' + $dt + '.csv' $SdelogFile = 'E:\Log\ShredLog_' + $dt +'.log' $sdelete = "C:\ADMIN\sdelete64.exe" $iterations = "-p 3" $dirs = 'E:\DIR1','E:\DIR2'Foreach ($dir in $dirs) {
Get-ChildItem $dir -File -Recurse | Where-Object {$.LastwriteTime -le “$Lastwrite”} | Select-Object Name, `
@{ n = ‘FilePath’; e = { Convert-Path $.PSPath } },`
@{ n = ‘LastWriteTime’ ; e = { $_.LastWriteTime } } |
Export-Csv -Path $CSVFile -Append -Encoding UTF8 -NoTypeInformation
}$Files = Import-Csv -Path $CSVFile | Select-Object -ExpandProperty FilePath | Where-Object { $_.PSObject.Properties.Value -ne $null}
Add-content $SdelogFile -value “----------------------------------------------------------------------------------------------------”
Add-content $SdelogFile -value “----------------------------------------------------------------------------------------------------”
Add-content $SdelogFile -value “Beginning run at: $Now”
Add-content $SdelogFile -value “Using sdelete command: $sdelete”
Add-content $SdelogFile -value “Sdelete iterations: $iterations”
Add-content $SdelogFile -value “----------------------------------------------------------------------------------------------------”
Add-content $SdelogFile -value “----------------------------------------------------------------------------------------------------”
ForEach ($File in $Files){
Add-content $SdelogFile -value “Shredding file: $file”
Add-content $SdelogFile -value “$sdelete $iterations $file”
$proc = Start-Process -FilePath $sdelete -ArgumentList “$iterations `”$file`"" -Wait -NoNewWindow -PassThru
Add-Content $SdelogFile -value “Sdelete exited: $($proc.HasExited)”
Add-content $SdelogFile -value “Sdelete return code: $($proc.ExitCode)”
}
$end = Get-date
Add-Content $SdelogFile -value “Ending at: $end”
Add-content $SdelogFile -value “----------------------------------------------------------------------------------------------------”