Specifically, I have a directory with a ton of other random named directories (Not really random but that's not important) in those directories some contain files with .tsidx extension, some do not. the directories which contain the tsidx extension I want to output to screen that it already exists. the ones that do NOT I want it to output it doesn't exist then run a command to build the tsidx files against the directory using an executable provided by vendor of a program. here is what is in my code so far:
$index = Read-Host "Enter the Index Name" #This is to receive a directory location from user
$loc = "F:\thawdb\splunk\$index\thaweddb"
$dir = dir $loc
cd "d:\splunk\bin"
foreach ($d in $dir)
{
if (gci -dir | ? { !(gci $_ -file -recur -filter *tsidx) })
{
Write-host -foregroundcolor Yellow "TSIDX Exists"
}
writes out the directory contains files and doesn't need rebuilt
else
{
write-host -Foregroundcolor Green "Running Rebuild command against $loc\$d" | .\splunk.exe rebuild $loc\$d
}
writes out rebuild is necessary and runs the rebuild
}
Aucun commentaire:
Enregistrer un commentaire