Forum Thread: Remove Files from the specified Folder Path

You are currently viewing a forum thread in the Secunia Community Forum. Please note that opinions expressed here are not of Secunia but solely reflect those of the user who wrote it.

This thread was submitted in the following forum:
CSI

This thread has been marked as locked.
umair9001 Remove Files from the specified Folder Path
Member 1st Oct, 2014 13:42
Ranking: 0
Posts: 5
User Since: 26th Mar, 2014
System Score: N/A
Location: QA
Last edited on 1st Oct, 2014 13:43

I found the following script which has helped me a lot in removing the vulnerable Files which are shown in Secunia. Those which I knew I could remove and didn't require to patch. The Host and FilePath are easily available through CSI export features.

This script uses powershell script to run. It requires a CSV file with the column headers as Host, Path and Status.

# CSV Needs Header row - Host,Path,Status
$csvPath = "C:\TheCsvFile.csv"
$csv = Import-Csv $csvPath
$csv | ForEach-Object {
$computer = $_.Host
$path = $($_.Path) -replace [char]34,""
$status = $_.Status
$props = @{
"Host" = $computer;
"Path" = $path;
"Status" = $status
}
$obj = New-Object -TypeName PSObject -Property $props
Write-Host "Processing computer $($computer.ToUpper())..."
if ($status -eq "") {
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
$dollarShare = $path -replace ":","$"
$uncPath = "\\$computer\$dollarShare"
if (Test-Path -Path $uncPath) {
$deleted = $true
try {
Remove-Item -Path $uncPath -Force
} catch {
$deleted = $false
$obj.Status = "Could not delete"
Write-Host " - failed to delete file."
}
if ($deleted) {
$obj.Status = "Deleted"
Write-Host " - removed file."
}
} else {
$obj.Status = "Missing"
Write-Host " - file not there."
}
} else {
Write-Host " - offline."
}
} else {
Write-Host " - already processed."
}
Write-Output $obj
} | Export-Csv -Path $csvPath -Force -NoTypeInformation

Thanks to the original creator of the script on Expert Exchange. http://www.experts-exchange.com/OS/Microsoft_Opera...

No one has replied to this thread yet - be the first
This thread has been marked as locked.