'Find a value in Excel via PowerShell

I have a script that find a row with a specific background color. I want to add a condition that if the cell has a color 14 and contains the word cab and I will copy it to a different folder. All the greens (color 14)will copy to other folder. currently all the green cells (14) copied to the same folder Maybe I need more if condition ? or one more object that holds all the cell that has color 14 and with the string inside? (patch is the name of the column) I need an object with all the 14 colors and one object with all the 14 colors and has a name like cab

$ExcelFile   = "C:\Temp\SharedFolder\Side VIP - Bulk Tool.xlsx" 
$searchValue = ''
$excel = New-Object -ComObject Excel.Application
$Excel.Visible = $false
$Excel.DisplayAlerts = $False # Disable comfirmation prompts
$workbook  = $excel.Workbooks.Open($ExcelFile)
$worksheet = $workbook.Worksheets.Item("VIP List")

# get the number of rows in the sheet
$rowMax = $worksheet.UsedRange.Rows.Count

# loop through the rows to test if the value in column 1 equals whatever is in $searchValue
# and capture the results in variable $result
$result = for ($row = 1; $row -le $rowMax; $row++) {
    $val = $worksheet.Cells.Item($row, 27).Interior.ColorIndex 
    if ($val -eq 14 -and $val -ne "cab")  {
        [PsCustomObject]@{Patch = $worksheet.Cells.Item($row, 1).Value2}
    }
}
write-host
-join("Number of patches:" + $result.count)
write-host

#$val = $worksheet.Cells.Item($row, 1).Interior.ColorIndex; if ($val -eq 3) { ... }

foreach ($res in $result)
{$vars = foreach ($res in $result) { "\\google.com\global\Patch Managment\$($res.patch)\*" }}

$des = "C:\Temp\SharedFolder\SideVIP"

foreach ($var in $vars)
{
    write-host $var
    Copy-Item -Path $var -include "*.VIP","*.ZIP"-Destination $des -Force
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source