Today I had to dust off my VMware and Powershell skills, using PowerCLI to get more information on 700+ Zombie Files that RVTools was reporting in a customer's environment! This is what I came up with;
##README
##First ensure you change values as appropriate in the section "#Hardcoded Stuff"##
#This script does nothing destructive - it gets information on zombie files as reported by RVTools
#The input file is expected to be prepared from an rvtools report by the following method;
#open rvtools report
#go to the vHealth sheet
#filter on column B ("Message") for the text "zombie"
#select all of column A ("Name")
#paste into a text file
#delete top line ("Name")
#save
#The output file needs to be somewhere you have write access to
#The output file is appended to each time, delete it if you need to run a clean report
#The output file's column 'LENGTH' IS IN KB SO 4685326 = 4.6MB
#Script written by james.griffiths@atos.net
#Hardcoded stuff - **CHANGE AS NECESSARY!!**
$datacenter = "Datacenter01"
$infile = "c:\users\jimg2\infile.txt"
$outfile = "c:\users\jimg2\outfile.csv"
#Open the input file and loop for each record
get-content $infile | foreach {
write-host "Processing line: $_"
#Get JUST Datastore (i.e. not filename or filepath) from input
$datastoreName = ($_ | Select-String '(?<=\[)[^\]]+(?=\])' -AllMatches).Matches.Value
Write-Host "Extracted Datastore: $($datastoreName -join ' ')"
#Get JUST filepath and filename (i.e. no Datastore) from input
$filePath = $input -replace '.*\]\s*', ''
Write-Host "Extracted FilePath: $($filePath -join ' ')"
#Change directory to datacenter and datastore
cd vmstore:\$datacenter
cd $datastoreName
#Change directory under datastore
# (First split $filepath by / to get subfolders recursively and skipping last record as this is the filename)
$arrFolders = $filePath.Split("/") | select-object -SkipLast 1 | foreach {
write-Host "Changing to folder: "($_)
cd $_
}
#Write file properties out
# (First split $filepath by / and select last item to get filename)
$arrFolders = $filePath.Split("/") | select-object -Last 1 | foreach {
write-Host "Outputting info for file: $_"
dir $_ | select Datastore,Name,FolderPath,Length,LastWriteTime | Export-Csv -Path $outfile -Append
}
}